Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Question about expandable pull down list  RSS feed

 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am trying to implement a pull down list using JComboBox. The problem is:
there are several hundreds of items in this list, user wish to see as many items as will fit in the physical screen display by grabbing the bottom right corner of the list and expanding the pull down vertically and horizontally. That is, they want to something similar to a browser or a text editor that you can grab the bottom right corner to expand as the phiysical screen will allow.

I have only used vertical or horizontal scroll bars. I just want to know if this is something I can achive using JComboBox. I wish some Swing guru can shed some lihg ton this?

thanks
 
Nick Meverden
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
final javax.swing.JComboBox cBox = new javax.swing.JComboBox();
cBox.addItem(new Object() {
public String toString() {
return "ONE";
}
});
cBox.addItem(new Object() {
public String toString() {
return "TWOTWOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO";
}
});


String[] data = new String[cBox.getModel().getSize()];
for (int x = 0; x < data.length; x++) {
data[x] = cBox.getModel().getElementAt(x).toString();
}

javax.swing.JList list = new javax.swing.JList(data);



cBox.setUI( new javax.swing.plaf.basic.BasicComboBoxUI() {
protected javax.swing.plaf.basic.ComboPopup createPopup() {
javax.swing.plaf.basic.ComboPopup popUp = new javax.swing.plaf.basic.BasicComboPopup(cBox) {
public javax.swing.JScrollPane createScroller() {
return new javax.swing.JScrollPane(list,
javax.swing.JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
javax.swing.JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
}
};
return popUp;
}


});

Here is an example I wrote using custom ComboBoxUI.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!