Create a custom components.
Hi everyone, it's me again.
I'm trying to develop a kind of personal messenger. What I would like to do now, it's to develop a Combobox allowing me to choose a smiley, a smiley picker.
I tried with a Renderer for a ComboBox but it does't work.
Can anyone help me to start this component, cuz I'm stuck :(
Thanks in advance.
BB.
[372 byte] By [
bbclonea] at [2007-10-2 21:17:30]

You have to set a JPanel as combo box renderer while keeping the values of the ComboBoxModel as string objects(or File objects) which are nothing but references to the .gif/.jpeg file path to be used to display the image through renderer. So that in getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) method you will receive particular String/File object as value param and that you can use to paint the image on JPanel and lastly you have to return this JPanel object.
Hitesh.
I tried that, but
- the width of the combobox is the same as the panel. I'd like that the size of the combobox is a little bigger that a picture size, and when I click on it, the panel dispalys a row of 5 smileys.
Do you have an example of what you said?
Thanks in advance.
> the panel dispalys a row of 5 smileys.
Sorry I don't have a code for what I said, but if you want to get the same effect as of MSN Messenger is giving then you have to twick the code. Instead of JComboBox, you have to take a JButton object with .gif image as icon and down arrow as text. At button click, you can show a popup menu. Now for row of 5 smilies, you have to make a top level main JPanel with GridLayout of 5 rows and in each grid you have to place a JPanel again with the smily icon. After that you have to set the main panel into popup by calling method, myPopupMenu.insert(mainPanel, 0). And then you can show this popup upon button click.
Hitesh