Re: how to refresh jComboBox in popupMenuWillBecomeVisible
- From: Rui <setprive@xxxxxxx>
- Date: Tue, 29 Aug 2006 21:45:43 +0200
Trufel a écrit :
hello,
i have jComboBox which should calculate its drop-down list size before
opening (it depends on current window size so I decide to put it into
popupMenuWillBecomeVisible method)
void jComboParamNames_popupMenuWillBecomeVisible(PopupMenuEvent e) {
int rowCount = 30; // sample for testing purposes...
myCombo.setMaximumRowCount(rowCount);
// how to refresh combo???
}
Desired size of drop down list will appear... after second click on the
comboBox. Is it possible to refresh it in popupMenuWillBecomeVisible
before showing drop-down list?
thanks
T.
From - Tue
If you intend to recalculate the size depending on the window size, better use ComponentListener on the container of your combo.
public class ComboSizeTest extends JFrame {
private static final String[] data = { "First", "Second", "Third",
"Fourth", "Fifth", "Sixth" };
JComboBox combo = null;
public ComboSizeTest() {
super("Test combo dropdown list resizing");
combo = new JComboBox(data);
this.addComponentListener(new ComponentAdapter() {
public void componentResized(ComponentEvent e) {
System.out.println("Resized");
combo.setMaximumRowCount(4);
}
});
this.setSize(100, 50);
this.getContentPane().add(combo, BorderLayout.CENTER);
}
public static void main(String[] args) {
new ComboSizeTest().setVisible(true);
}
}
NB: I added a setSize() method after adding the ComponentListener to insure that combo size will be calculated before the frame is made visible.
Rui.
.
- Follow-Ups:
- References:
- Prev by Date: Re: JComboBox into JHeader
- Next by Date: Looking for Sr. Java Engineers for Internet Advertising Company in Mountain View,CA
- Previous by thread: how to refresh jComboBox in popupMenuWillBecomeVisible
- Next by thread: Re: how to refresh jComboBox in popupMenuWillBecomeVisible
- Index(es):
Relevant Pages
|