• Post Reply Bookmark Topic Watch Topic
  • New Topic

Positioning the scroll bar..

 
Tris Rabar
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello..
I'm having a lil problem, as follows:
I have a JTextArea within a JScrollPane. I keep refreshing the JTextArea with new text, so each time after I refresh the textarea, the scrollbar is positioned at the bottom of the textarea. Is there a way to automatically position it at the top after each refresh?
Also, can two or more components be placed within the same JScrollPane?
Thanks!
 
Tris Rabar
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I need some urgent help!!
Thanks!
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The JViewport class has a method called scrollRectToVisible() that you can call when you update your text area. JScrollPane has a method called getViewport() that will let you get a reference to the viewport of your JScrollPane.

Only one component per scroll pane... but that one component can be a JPanel that contains two (or more...) components.

-Nate
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!