dcsimg
Login | Register   
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.


Tip of the Day
Language: Java
Expertise: Intermediate
Apr 2, 2001

WEBINAR:

On-Demand

Application Security Testing: An Integral Part of DevOps


Customizing an Editable JComboBox


A previous tip explained how to change the appearance of the 'list selection' cells of a JComboBox by setting the attributes of the JComboBox object's ListCellRenderer.

However, the ListCellRenderer controls the item area for a non-editable JcomboBox. A ComboBoxEditor controls the item area for an editable JcomboBox (which, in turn, contains a component that handles the visual aspect of the JComboBox.) Here is how you might change the background color of the editable area of a JComboBox:
 
ComboBoxEditor cbe = cb.getEditor();
Component c = cbe.getEditorComponent();
c.setBackground(Color.red);

When the JComboBox is not editable (which is the default) then the standard method 'cb.setBackground(...)' will work, but it has the side effect of also changing the background colors of the arrow button and the individual unselected cells in the selection list area. Setting the color on the default ListCellRenderer has no effect because the renderer's colors are adjusted during repainting (remember
Roy Lachapelle
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date