wood burning stoves 2.0*
The moose likes Swing / AWT / SWT and the fly likes automatic scrolling of JTextField Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "automatic scrolling of JTextField" Watch "automatic scrolling of JTextField" New topic
Author

automatic scrolling of JTextField

Anthony Yulo
Ranch Hand

Joined: Feb 22, 2003
Posts: 52
Ei! How can I make a JTextField automatically scroll when my Text is longer than the width of my JTextField... Isn't this supposed to be automatic for the JTextField?


it's alright, the gun isn't loaded... - hey
Candy Bortniker
Ranch Hand

Joined: Mar 17, 2003
Posts: 123
You need to put the JTextField on a ScrollPane like this:
Chantal Ackermann
Ranch Hand

Joined: Sep 28, 2000
Posts: 508
hi,
do you mean horizontal scrolling? I suppose so, as JTextField has only one row. what exactly do you mean by automatic? That the cursor (if any) is always visible, and the user can scroll by hitting the arrow left and right keys? that should work.
you can influence the initial placement of the text by either setting the horizontal alignment or placing the cursor (in the Document) explicitely, for what I remember.
Chantal
Steve Winer
Greenhorn

Joined: Oct 30, 2001
Posts: 6
JTextArea does not automatic scrolling, so you have to extend it with your own class that does this. This is easy to do by adding a DocumentListener that sets the caret position to the end of the text when the document's content changes.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: automatic scrolling of JTextField