Re: Can I put JLabel array in JComboBox?
- From: "Bart Cremers" <bcremers@xxxxxxxxx>
- Date: 26 Apr 2006 22:44:51 -0700
Of course you can, although I don't see the use for it in your example.
The default renderers and editors for a JComboBox are designed to work
with Strings and primite wrappers, so in your example it would be
better to add an array of Double objects to the combobox:
Double[] items = new Double[4];
....
c.intems[0] = new Double(5.25);
....
pane.add(new JLabel(c.items[0].toString()), BorderLayout.CENTER);
....
This should render perfectly.
If you want for some obscure want to add an array of JLabels you'll
have to override the renderer (c.comboBox.setRenderer(subclass of
DefaultListCellRenderer). More work is involved even if you want the
combobox also to be editable. This requires you to set the editor on
the combobox (c.combBox.setEditor(implementation of ComboBoxEditor). As
you can see a lot of work while you probable gain nothing from it.
Bart
.
- References:
- Can I put JLabel array in JComboBox?
- From: niceguy16
- Can I put JLabel array in JComboBox?
- Prev by Date: Re: Thinlet GUI toolkit question
- Next by Date: JTextPane newb
- Previous by thread: Can I put JLabel array in JComboBox?
- Next by thread: Re: Can I put JLabel array in JComboBox?
- Index(es):
Relevant Pages
|
|