Re: Can I put JLabel array in JComboBox?



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

.



Relevant Pages

  • Re: JComboBoxes in a JTable
    ... I found this article quite helpful when I had to wrestle with renderers and ... editors in JTables a while back; I don't remember many of the details but I ...
    (comp.lang.java.help)
  • Layered panel
    ... I need to provide some complex in-place cell table editors. ... corresponding renderers are ok for a standard cell height but the ... general solution. ...
    (comp.lang.java.gui)
  • Layered panel
    ... I need to provide some complex in-place cell table editors. ... corresponding renderers are ok for a standard cell height but the ... general solution. ...
    (comp.lang.java.gui)
  • Re: Different combo boxes are cell editors
    ... example on the java website: ... TableColumn sportColumn = table.getColumnModel.getColumn; ... same type and subject to the same renderers and editors. ...
    (comp.lang.java.programmer)