Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Only part of text in JTextField is visible 1

Status
Not open for further replies.

YerMom

Programmer
Oct 3, 2006
127
US
I have a GUI application that includes a JTextField, which is disabled because I don't want the user to type in the field.

I set the text dynamically, but when the text exceeds the length of the JTextField, then only the last part of the text is visible. I prefer to have the user see the start of the text and have the remainder not visible becuase I can use a tooltip to display the entire contents.

Is there a way to have the first part of the text visible?

Thanks.
 
you may try this method when you want to scroll to first part.
yourJTextField.setScrollOffset(0);
 
So you have a disabled TextField that the user cannot see and has to use a tooltip?

I'd reconsider that design

Cheers,
Dian
 
prosper,
setScrollOffset did not work, but setCaretPosition does work.

Dian,
Thanks for your suggestion. Your feedback is always welcome. The story is this: the text field contains a path that I let the user set by displaying a JFileChooser. I considered not disabling the text field and giving the user the option to type a path, but that leaves open the possibility of entering an invalid path, so I decided to disable the text field. Do you have any suggestions?

 
What I don't like is the idea of a textfield whose content I cannot see. You can scroll even if it's disabled. I'm not sure, but maybe a BoundedRangeModel would do the trick or maybe it's just OK for your needs, this is just a personal opinion.

Cheers,
Dian
 
I'm certainly no one to throw criticisms but isn't this an instance of where "Label" is indicated (instead of TextField)?

_________________
Bob Rashkin
 
Bob,

I don't understand your question. The component in question is a JTextField.

Thanks,
Steve
 
If I want to display text that the user can't edit, I use a Label widget (or JLabel in swing).

_________________
Bob Rashkin
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top