MyEclipse Forums
Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Author Message
pbassi
Post subject: JComboBox renderer problem  PostPosted: Nov 26, 2009 - 04:49 PM
Registered Member
Registered Member


Joined: Mar 15, 2007
Posts: 24

Hi,

can anybody help me understand why the combobox renderer below is setting the background color correctly, but not the foreground one?

Thanks in advance.
Paolo

Code:
public class BUComboBox extends JComboBox {

   public BUComboBox(ComboBoxModel aModel) {
      super(aModel);
      ComboBoxRenderer renderer= new ComboBoxRenderer();
      renderer.setPreferredSize(new Dimension(200, 20));
      this.setRenderer(renderer);
   }

   private class ComboBoxRenderer extends JLabel implements ListCellRenderer {
      public ComboBoxRenderer() {
         setOpaque(true);
      }

      public Component getListCellRendererComponent(
            JList list,
            Object value,
            int index,
            boolean isSelected,
            boolean cellHasFocus) {

         if (isSelected) {
            setBackground(Color.BLUE);
            setForeground(Color.WHITE);
         } else {
            setBackground(Color.WHITE);
            setForeground(Color.BLUE);
         }
         return this;
      }
   }
}
 
 View user's profile Send private message  
Reply with quote Back to top
pbassi
Post subject: JComboBox Renderer Problem - SOLVED  PostPosted: Nov 26, 2009 - 05:47 PM
Registered Member
Registered Member


Joined: Mar 15, 2007
Posts: 24

Forget about the question, I found the problem, I was not setting the value in the renderer...

Thanks!
 
 View user's profile Send private message  
Reply with quote Back to top
Display posts from previous:     
Jump to:  
All times are GMT - 6 Hours
Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Powered by PNphpBB2 © 2003-2004 The PNphpBB Group
Credits