File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "automatic scrolling of JTextField" Watch "automatic scrolling of JTextField" New topic

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
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.
Steve Winer

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.
I agree. Here's the link:
subject: automatic scrolling of JTextField
It's not a secret anymore!