For example, the user select "cat" from the list of JComboBox, it then fire up an event to load some texts in some of the text boxes. When the user change the content of one of the boxes, the JComboBox (with the selected item is "cat") flash (red color maybe) to indicated that the content of "cat" has been change. That the user need to save. How can I do that? I have done something similar in C# using Window Form Validated and Validating, but somehow it is much harder in java. I been looking around but nothing come close to what I want. Thanks in advance
I don't think it is possible to make it "flash" so to speak. However, if you can change the color of the text for the JComboBox item then you may want to look into Timer class of swing. With Timer class, you can then change the color of the item in say 1sec interval making it look like flashing
I think I run into a problem, here is the quote from the website that you send me
"Be careful when implementing a custom model for a combo box. The JComboBox methods that change the items in the combo box's menu, such as insertItemAt, work only if the data model implements the MutableComboBoxModel interface (a subinterface of ComboBoxModel). "
This mean that if I implement custom render to the JComboBox, it will make the JComboBox become immutable, is this correct? Meaning that if I implement custom render, I cant insert item or delete item from the JComboBox List?
If this is the case, then custom render will not be the way for me to go? I constantly insert and delete item from the list. Is there another route to accomplish what I want?
Thang Pham wrote:This mean that if I implement custom render to the JComboBox, it will make the JComboBox become immutable, is this correct? Meaning that if I implement custom render, I cant insert item or delete item from the JComboBox List?
I think that your confusing renderers with models. Please understand that they are two completely different things, and one shouldn't effect the other. Why not try playing with creating a custom renderer and seeing what happens? You've nothing to lose here.
You may have to create some custom ComboBoxUI eg. extends from BasicComboBoxUI and add MouseListener to the list (JList) which is communicating with your ListCellRenderer. Something like that I think...
I'm not sure if your code suppose to perform anything different than mine, but when I add the main class and run it, it performs exact like mine. That when I click on the down arrow button, a list pop out, then when I roll mouse over the items of the list, it changes the background color of that item to RED, but when I select that item, the list close up, but the color of the selected item changes back to light blue (the system original selection color). It is no longer RED anymore.
> then when I roll mouse over the items of the list, it changes the background color of that item to RED,
> but when I select that item, the list close up, but the color of the selected item changes back to light blue (the system original selection color).
seems you need a combination of
box.setBackground(Color.RED);
box.setForeground(Color.GREEN);
and
UIManager.put("ComboBox.selectionBackground",new javax.swing.plaf.ColorUIResource(Color.RED));
UIManager.put("ComboBox.selectionForeground",new javax.swing.plaf.ColorUIResource(Color.GREEN));
and
your renderer
the UIManager lines MUST be before you create the comboBox
What I don't understand is how they changed the earth's orbit to fit the metric calendar. Tiny ad: