Hi Paolo,

>I didnt think so, because i tried using the value, but i always have a
>call with row=-1 and value=null. The selected item on combobox is always
>based on that returned template!! :-(

Did you try the snippet I sent you? I am sending it again (see at the end of
this mail). Please try it.

Call for row = -1 and value = null is generated to get the renderer for the
combobox itself. In this case you return the renderer for the 1st item in
the combo's drop dow list. Initially, when nothing is selected the combobox
show the 1st value, so we return the renderer for the first value.

Please note the following stmt in the snippet below:

           int val = (value != null) ? ((Integer)value).intValue() : 0;

I hope this helps.

Thanks and regards,

Janak

>-----Original Message-----
>From: Paolo Scaffardi [mailto:[EMAIL PROTECTED]
>Sent: Friday, August 18, 2006 11:32 AM
>To: Janak Mulani
>Cc: [email protected]
>Subject: Re: [ULC-developer] ULC6.1: ULCComboBox renderer issue...
>
>
>Janak Mulani ha scritto:
>> Hi Paolo,
>>
>> You can choose renderers based on the value. In this case you
>need not worry
>> about indices including -1.
>
>I didnt think so, because i tried using the value, but i always have a
>call with row=-1 and value=null. The selected item on combobox is always
>based on that returned template!! :-(
>
>What does value==null and row=-1 means? I need to let the user select
>items with different icons and styles from the combobox that, when
>selected, looks identical on the combobox cell.
>
>Is it possibile? :-o
>
>>
>>
>>> -----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
>
>Best regards,
>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();
    }
}

Attachment: collapse.gif
Description: GIF image

Attachment: expand.gif
Description: GIF image

Attachment: flag_red.gif
Description: GIF image

Reply via email to