Results 1 to 3 of 3
Thread: JScrollPane and viewport issues
- 10-14-2011, 11:14 PM #1
Member
- Join Date
- Oct 2011
- Posts
- 1
- Rep Power
- 0
JScrollPane and viewport issues
Hi all,
I am trying to create a UI that uses GridLayout. As a part of this UI I've created a JTextArea and added it to a JScrollPane. I then add text to the text area through out the program using .append() However, the text area keeps expanding down out of a viewable area. I want the text to scroll upward as new text is added but I can not figure out for the life of me how to make this happen. I've tried several different setting i.e. (setMaximumSize() or setPrefferedSize() but neither seem to work.
Here is a sample of the code:
//set text area
jta_area = new JTextArea();
jta_area.setBackground(null);
jta_area.setFont((Font) Game.f);
jta_area.setColumns(15);
jta_area.setAutoscrolls(true);
jta_area.setEditable(false);
combatScroll = new JScrollPane(jta_area);
//combatScroll.getViewport().setScrollMode(0);
Dimension d = new Dimension(15,15);
combatScroll.setPreferredSize(d);
combatScroll.setMaximumSize(d);
Any help you give can give me is much appreciated
Thanks
-
Re: JScrollPane and viewport issues
What if wherever you are appending to the JTextArea, you add a line after this that sets the caret position to the end of the document:
Java Code:jta_area.append("whatever you're adding\n"); // *** add code below *** jta_area.setCaretPosition(jta_area.getText().length()); // to place the caret at end of doc
- 10-15-2011, 11:03 PM #3
Similar Threads
-
JScrollPane issues - no autoscroll wished
By Flo in forum AWT / SwingReplies: 3Last Post: 08-18-2011, 01:17 PM -
Need Help With JScrollPane Please
By MemorableSmile in forum New To JavaReplies: 4Last Post: 01-31-2011, 02:39 AM -
Zoom map in JScrollPane, keep center of viewport
By knuth in forum New To JavaReplies: 0Last Post: 10-01-2009, 07:45 PM -
jscrollpane scroll issues
By kumar_gemi in forum AWT / SwingReplies: 11Last Post: 09-30-2009, 08:33 PM -
help with JScrollPane
By tommy in forum AWT / SwingReplies: 1Last Post: 08-06-2007, 07:58 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks