• Post Reply Bookmark Topic Watch Topic
  • New Topic

Misbehaving JScrollPane  RSS feed

 
Paul Fonz
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a JScrollPane that displays a JList which is showing the contents of a Vector. I initialise the vector, create the JList and create the JScrollPane, and everything displays and appear perfectly. However, when i dynamically add an element to the vector at runtime, the JScrollPane doesn't scroll properly, and won't let me change the selection.
I have tried the update() updateUI() and revalidate() methods of the JScrollPane, and they make noe difference. Does anybody know how to fix this?
Probably not much use, here is the section of code:
 
Paul Fonz
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A solution occurred to me while I was writing that topic, and I think I've solved it. I don;t know if this is the correct way of doing things, but I re-initialised the JList and then re-set the JScrollPane ViewportView.
It looks like it's solved the problem...
 
Chantal Ackermann
Ranch Hand
Posts: 508
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the scrollpane should update automatically. It is not necessary to call revalidate(), update() or anything like this. If you cannot select items in the list this is rather caused by a bug in your use of JList.
To scroll the list to the newly entered item, you can set the value of the vertical scrollbar to its maximum (if you can be sure, that any new event is entered at the bottom). or you have to retrieve the coordinates of the new item from the list, and use scrollRectangleToVisible from JViewport.
Chantal
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!