Hi Paolo, You can choose renderers based on the value. In this case you need not worry about indices including -1.
Please see the snippet at the end of this mail. I hope this helps. Thanks and regards, Janak >-----Original Message----- >From: [EMAIL PROTECTED] >[mailto:[EMAIL PROTECTED] Behalf Of Paolo Scaffardi >Sent: Tuesday, August 08, 2006 10:54 PM >To: [email protected] >Subject: [ULC-developer] ULC6.1: ULCComboBox renderer issue... > > >I tried to use a custom renderer for a combobox, to set the combobox >entries icon. > >But i discovered the renderer method is called with a invalid row value >(-1). That call seems to be needed to render the selected combobox item >(once). > >Why that? Why my entries have icons on combobox popup but none when >selected on the combobox? This is my renderer: > >public IRendererComponent getComboBoxCellRendererComponent(ULCComboBox >combo, Object value, boolean selected, int index) { > ret.setIcon(index==-1? null : modelIcons[index])); > return ret ; >} > >How can i fix it? The only workaround i could imagine is to use a >"decorated" value field instead of the index one to get current index >instead of the -1 value. > >What can i do? > >Paolo Scaffardi >GFP Lab s.r.l. >http://www.gfplab.com >fax 178 2258454 ----------------------------------------- import com.ulcjava.base.application.AbstractApplication; import com.ulcjava.base.application.IComboBoxCellRenderer; import com.ulcjava.base.application.IRendererComponent; import com.ulcjava.base.application.ULCBoxPane; import com.ulcjava.base.application.ULCComboBox; import com.ulcjava.base.application.ULCFrame; import com.ulcjava.base.application.ULCLabel; import com.ulcjava.base.application.util.Color; import com.ulcjava.base.application.util.ULCIcon; import com.ulcjava.base.development.DevelopmentRunner; public class IComboBoxCellRendererSnippet extends AbstractApplication { public void start() { // snippet: combo box Integer[] values = getAvailableValues(); ULCComboBox comboBox = new ULCComboBox(values); comboBox.setRenderer(new SampleRenderer()); // snippet: end ULCBoxPane content = new ULCBoxPane(true); content.add(ULCBoxPane.BOX_EXPAND_CENTER, comboBox); ULCFrame frame = new ULCFrame("IComboBoxCellRendererIndexSelSnippet"); frame.setDefaultCloseOperation(ULCFrame.TERMINATE_ON_CLOSE); frame.add(content); frame.setSize(200, 100); frame.setVisible(true); } // snippet: combo box private static class SampleRenderer implements IComboBoxCellRenderer { private ULCLabel fLabel; public SampleRenderer() { fLabel = new ULCLabel(); fLabel.setOpaque(true); } public IRendererComponent getComboBoxCellRendererComponent(ULCComboBox comboBox, Object value, boolean isSelected, int row) { int val = (value != null) ? ((Integer)value).intValue() : 0; if (val == 0) { fLabel.setBackground(Color.blue); fLabel.setIcon(new ULCIcon(IComboBoxCellRendererIndexSelSnippet.class.getResource("flag_red.gif "))); fLabel.setHorizontalAlignment(ULCLabel.LEFT); } else if (val == 1) { fLabel.setBackground(Color.pink); fLabel.setIcon(new ULCIcon(IComboBoxCellRendererIndexSelSnippet.class.getResource("collapse.gif "))); fLabel.setHorizontalAlignment(ULCLabel.RIGHT); } else if (val == 2) { fLabel.setBackground(Color.orange); fLabel.setIcon(new ULCIcon(IComboBoxCellRendererIndexSelSnippet.class.getResource("expand.gif") )); fLabel.setHorizontalAlignment(ULCLabel.CENTER); } return fLabel; } } private Integer[] getAvailableValues() { Integer[] result = new Integer[3]; for (int i = 0; i < result.length; i++) { result[i] = new Integer(i); } return result; } public static void main(String[] args) { DevelopmentRunner.setApplicationClass(IComboBoxCellRendererSnippet.c lass); DevelopmentRunner.run(); } } _______________________________________________ ULC-developer mailing list [email protected] http://lists.canoo.com/mailman/listinfo/ulc-developer
