• Post Reply Bookmark Topic Watch Topic
  • New Topic

Scrolling JComboBox popup to show selected item at top  RSS feed

 
Pete Tibbitts
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I'm using a JComboBox which contains many items in its model. Im programmatically selecting the selected item using syntax such as.....

When I do this, the combo popup automatically scrolls to show the selected item in the popup view. However, the popup menu only scrolls 'just far enough' to display the item so it is usually displayed at the bottom of the view. (I've knocked up some test code which i've attached below to demonstrate the behaviour).
Is there a way that I can get the combo/popup to scroll so that the selected item is at the displayed at the top of the popup view???
Any help would be much appreciated!!
 
Daniel Puryear
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You'll need to implement you own flavor of the list model used by the JCombobox to re-order or "map" the indices in the model. Specifically, "extend AbstractListModel implements MutableComboBoxModel"
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!