Background, Foreground of JComboBox

Hi,
I'm having trouble formatting. I have an array of Strings in a JComboBox in a BasicComboPopup appearing in a JTextPane. The popup works fine, but I'd like to set the background and foreground colors of the popup to different colors from their defaults.
Currently, I'm trying this:
String [] myDisplayItems = { "Riker", "LaForge", "Picard" };
JComboBox box = new JComboBox(myDisplayItems);
BasicComboPopup popup = new BasicComboPopup(box);
box.setBackground(Color.YELLOW);
box.setForeground(Color.RED);
popup.setBackground(Color.YELLOW);
popup.setForeground(Color.RED);
box.setVisible(true);
popup.show(this, 100, 100);
After setting color, if I print getBackground().toString() or getForeground().toString() I get the correct RGB values. However, when the box pops up, the colors I set do not appear.
Am I doing something wrong? What's the correct way to do this?
All help appreciated. Cheers.

Try:
UIManager.put("ComboBox.background",Color.YELLOW);
UIManager.put("ComboBox.foreground",Color.RED);
before you create any combobox.
;o)
V.V.

Similar Messages

  • Background\Foreground settings

    Hi Friends,
    I have an application in which there are a few screen Layouts designed.
    Now i need to set the same Color of the screen to the Background\Foreground so that all the empty Spaces can be filled out(At present these bounderies are in White Color).
    So plz do let me know about how I can change the settings in my application.
    Thanks and regards,
    Chandrashekar.

    Hi,
    Refer these links...
    /people/lisha.peter/blog/2005/07/07/make-your-webdynpro-application-theme-specific
    https://sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/library/uuid/ccb6bcf4-0401-0010-e3bc-ec0ef03e13d1
    https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/library/webdynpro/wd%20java/colourful%20webdynpro%20applications.pdf
    Regards,
    karthik.

  • Set Background/Foreground color for Cell Renderer in JComboBox

    Hello,
    I was wondering if there is a way to change default settings for when I browse items under a JComboBox's cell renderer? I want the item's color to change (to what I set it to), when mouse enters the item. As of now, the cell's background color changes to Blue when I enter it. Is this default for JComboBox or might it have been set somewhere, that I need to look into?
    Please let me know if there are ways to do this.
    Thanks!
    Message was edited by:
    programmer_girl

    Here's my SSCCE:
    import java.awt.Color;
    import java.awt.Dimension;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.awt.event.MouseAdapter;
    import java.awt.event.MouseEvent;
    import javax.swing.JFrame;
    import javax.swing.JComboBox;
    import javax.swing.JPanel;
    import javax.swing.JTextField;
    import javax.swing.text.DefaultHighlighter;
    public class MyComboBoxTest extends JPanel {
          * @param args
         String[] patterns = {"pattern1","pattern2","pattern3"};
         public MyComboBoxTest()
              JPanel patternsPanel = new JPanel();
            setMinimumSize(new Dimension(100, 100));
            JComboBox patternList = new JComboBox(patterns);
            final JTextField editor = (JTextField) patternList.getEditor().getEditorComponent();
            patternList.setEditable(true);
            this.add(patternsPanel);
            patternsPanel.add(patternList);
            patternList.addActionListener(new ActionListener()
                 public void actionPerformed(ActionEvent e)
                      editor.setSelectedTextColor(Color.WHITE);
                      editor.setForeground(Color.WHITE);
                      try{
                           editor.getHighlighter().addHighlight(0, editor.getText().length(),new DefaultHighlighter.DefaultHighlightPainter(Color.BLUE));
                           } catch (Exception ex){
                                ex.getMessage();
            editor.addMouseListener(new MouseAdapter()
                 public void mouseClicked(MouseEvent e)
                      editor.getHighlighter().removeAllHighlights();
                      editor.setForeground(Color.BLACK);
                      editor.setSelectedTextColor(Color.BLACK);
         public static void main(String[] args) {
              // TODO Auto-generated method stub
              JFrame frame = new JFrame("My ComboBox Demo");
              frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
            frame.setSize(100, 100);
            frame.getContentPane().add(new MyComboBoxTest());
            frame.setLocation(50, 50);
            frame.pack();
            frame.setVisible(true);
    }

  • Midlet running in the background/foreground

    i would like to know if it is possible to have a midlet running on for example a mobile phone - and this midlet runs in the background and as soon as certain parameters meet each other the midlet will be in the foreground again ... also i want to know if its possible to switch between foreground and background - for example with a hotkey.

    Unless device specifically supports it then no.

  • Cant change color on visited sites without changing background /foreground colors that hide options on the sitec

    I want to change the color of visited sites, but am forced to set background and foreground colors which don't properly
    show all of the colors for controls etc on many websites.
    I have to uncheck the button to Allow pages to choose their own colors....
    Google is a good example after doing a search, then change visited sites color, uncheck the allow pages button and then you can't see the search button and most of the options in the top right corner in google.
    I am a little color blind, so can't differentiate blue and purple for links on visited sites...
    thx

    I think the problem is that many sites use background colors to create buttons, so you lose that when you override the page's colors.
    Maybe you could use an add-on to fine-tune colors instead of Firefox's all-or-nothing setting. I found a couple extensions that say they can change page colors, but I haven't tried them myself:
    * [https://addons.mozilla.org/firefox/addon/color-that-site/ Color That Site!]
    * [https://addons.mozilla.org/firefox/addon/colorific-1/ Colorific]
    * [https://addons.mozilla.org/firefox/addon/toggledocumentcolors-198916/ ToggleDocumentColors_]
    * [https://addons.mozilla.org/firefox/addon/color-toggle/ Color toggle]
    For a truly custom approach to link colors, there are two general purpose ways to apply your own style rules to specific sites: the Stylish extension and a userContent.css files. You would need to set a preferred text ''and'' background color for visited and unvisited links so that you are guaranteed to be able to read the text.
    Hope one of these fits the bill!

  • Images not showing in firefox (background & foreground)

    Was workiing on a client's computer and noticed that background images and some foreground images didn't load in Firefox.
    I researched and tried a number of suggested solutions, but none of them worked. I even updated to newest version of firefox in an attempt to resolve the probem, but still nothing.
    As a side note the images do load with other browers, so I am a but confused as result.

    If images are missing then check that you do not block images from some domains.
    *Press the F10 key or tap the Alt key to bring up the hidden Menu bar.
    Check the permissions for the domain in the currently selected tab in "Tools > Page Info > Permissions"
    Check "Tools > Page Info > Media" for blocked images
    *Select the first image link and use the cursor Down key to scroll through the list.
    *If an image in the list is grayed and "<i>Block Images from...</i>" has a checkmark then remove this checkmark to unblock images from this domain.
    Make sure that you do not block (third-party) images, the <b>permissions.default.image</b> pref on the <b>about:config</b> page should be 1.
    Make sure that you haven't enabled a High Contrast theme in the Windows/Mac Accessibility settings.
    Make sure that you allow pages to choose their own colors.
    *Edit > Preferences > Content : Fonts & Colors > Colors : [X] "Allow pages to choose their own colors, instead of my selections above"
    Note that these settings affect background images.
    See also:
    *http://kb.mozillazine.org/Website_colors_are_wrong
    There are extensions like Adblock Plus (Firefox/Tools > Add-ons > Extensions) and security software (firewall, anti-virus) that can block images and other content.
    See also:
    *https://support.mozilla.org/kb/Troubleshooting+extensions+and+themes
    *http://kb.mozillazine.org/Images_or_animations_do_not_load
    *http://kb.mozillazine.org/Websites_look_wrong

  • How do I add "change background/foreground color" to the configurator, and color buttons?

    How do I add "change background color" and "change foreground color" in the configurator?
    Also is there a way to color buttons?
    Regards,
    Glen

    No matter whether you mean the application Configurator or a Panel created with Configurator you would probably do well to post the question on the Configurator Forum.
    Configurator

  • No success in placing background image in JComboBox drop-down!

    Hi All! I have an urgent proble, which I was not able to resolve a full day and a half long!!! I want to place a background image in the dropdown (JPopupMenu) of a JComboBox. Not behind the Menu Items (I know how to do that), but behind the popup itself (the items will have a transparent background). I was surprised to find out that I cannot achieve this via UI delegates (seems paint takes place in JComponent), nor with simply subclassing JPopupMenu (because after I draw the image it is overwritten by a background rectangle). I beleive this is not an easy thing to acheive, but I would accept a complicated solution as well.
    Can anyone help me?
    Thanks, in advance!

    Try this for ideas. Change the filename to a valid image file on your machine.import java.awt.Color;
    import java.awt.Component;
    import java.awt.Graphics;
    import java.awt.Image;
    import java.awt.event.InputEvent;
    import java.awt.event.MouseEvent;
    import java.io.File;
    import java.io.IOException;
    import javax.imageio.ImageIO;
    import javax.swing.DefaultListCellRenderer;
    import javax.swing.JComboBox;
    import javax.swing.JFrame;
    import javax.swing.JList;
    import javax.swing.SwingUtilities;
    import javax.swing.plaf.basic.BasicComboPopup;
    import javax.swing.plaf.basic.ComboPopup;
    import javax.swing.plaf.metal.MetalComboBoxUI;
    public class PictureCombo {
       public static void main(String[] args) {
          SwingUtilities.invokeLater(new Runnable() {
             @Override
             public void run() {
                new PictureCombo().makeUI();
       public void makeUI() {
          Object[] data = {"One", "Two", "Three", "Four", "Five"};
          JComboBox comboBox = new JComboBox(data);
          comboBox.setUI(new PictureComboBoxUI());
          comboBox.setRenderer(new PictureListCellRenderer());
          JFrame frame = new JFrame();
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          frame.add(comboBox);
          frame.pack();
          frame.setLocationRelativeTo(null);
          frame.setVisible(true);
    class PictureComboBoxUI extends MetalComboBoxUI {
       @Override
       protected ComboPopup createPopup() {
          return new PictureComboPopup(comboBox);
    class PictureComboPopup extends BasicComboPopup {
       Image image;
       public PictureComboPopup(JComboBox comboBox) {
          super(comboBox);
          try {
             image = ImageIO.read(new File("E:/Java/test.jpg"));
          } catch (IOException ex) {
             ex.printStackTrace();
       @Override
       protected JList createList() {
          JList retVal = new JList(comboBox.getModel()) {
             @Override
             public void processMouseEvent(MouseEvent e) {
                if (e.isControlDown()) {
                   e = new MouseEvent((Component) e.getSource(), e.getID(), e.
                         getWhen(),
                         e.getModifiers() ^ InputEvent.CTRL_MASK,
                         e.getX(), e.getY(),
                         e.getXOnScreen(), e.getYOnScreen(),
                         e.getClickCount(),
                         e.isPopupTrigger(),
                         MouseEvent.NOBUTTON);
                super.processMouseEvent(e);
             @Override
             protected void paintComponent(Graphics g) {
                if (image != null) {
                   g.drawImage(image, 0, 0, comboBox);
                super.paintComponent(g);
          retVal.setOpaque(false);
          return retVal;
    class PictureListCellRenderer extends DefaultListCellRenderer {
       @Override
       public Component getListCellRendererComponent(JList list, Object value,
             int index, boolean isSelected, boolean cellHasFocus) {
          super.getListCellRendererComponent(list, value, index, isSelected,
                cellHasFocus);
          Color selBgColor = list.getSelectionBackground();
          selBgColor = new Color(selBgColor.getRGB() & 0xA0FFFFFF, true);
          setBackground(selBgColor);
          setOpaque(isSelected);
          return this;
    }db

  • Master background/foreground

    After 58 views and no responses, I am editing post this to better explain my particular misunderstanding of heirachy in this new version of the Muse application.
    This is my working example uncovered by accident on the 31st of January: nv-cpc.org
    Select the top link leading to teen dating violence.  That B-Master is background.
    Select the bottom link leading to home page.  That A-Master is foreground.
    The site was designed with 15 master pages, mixed foreground and background using Muse v5 & v6.
    I have zero idea of how to manipulate the heirachy relationship now between master and subordinate pages, since all the pages are nearly identical in build.
    Does that make sense?
    Heirachy is a simple concept in layers.  The higher the layer, the higher the object will be on the page.
    What I am apparently misunderstanding is the heirachy relationship between master and subordinate pages and how to manipulate that relationship with the current layers panel.
    I am following the concept of heirachy in master pages.
    I am still lost with the concept of creating layers on a subordinate or master page to manipulate the subordinate or master.
    I am just missing the obvious.
    Thanks for any suggestions.
    Michael
    Message was edited by: Michael K Corti
    Message was edited by: Michael K Corti

    Brad,
    I may be looking at this wrong. I am an AE, Photoshop, AI, ID, and FCP user. I read in the forums this new v7 layering concept is different from the models I am familiar with.
    Your layering appears to control a single page.
    I am not understanding the interaction between master and subordinate pages from your example.
    I understand your example to be a perfect layering model for an individual page.
    1. All the header objects are locked in your header layer.
    2. All of the footer objects are locked in your footer layer.
    3. Unlocked page content is stored/edited in your Content layer.
    I am NOT understanding how or where Master/Subordinate page objects fit into your layering model.
    This is my example: http://nv-cpc.org/daterape.html
    1. On "B-Master" I have LOGO, MENU in a single layer in heirachy.
    2. On "daterape" I have objects in a single layer in heirachy.
    I orignially set up B-Master objects as foreground, Daterape objects are background.
    This is my alternate example: http://nv-cpc.org/bouldercity.html
    1. On "BC-Master" I have LOGO, Header Item, Menu Objects, Background Image.
    2. On "Bouldercity" I have four menu objects.
    I originally set up BC-Master objects as background, Bouldercity objects are foreground.
    Question:
    How do I create a layer for subordinate pages? That seems counter intuitive.
    How do I create a layer for Master pages? That seems counter intuitive as well.
    In your example, your layering appears to control a single page.
    I am not understanding the interaction between master and subordinate pages in your example.

  • Background & Foreground Processing

    Hi All,
        Can anyone tell me how to switch a program to foreground mode when it is running in background mode & vice-versa.
    Regards,
    Santosh

    In BDC its Possible,
    Say you are using three Transactions:ME51,ME21,ME22.
    Create a session.
    Sequence:
    ME51
    ME21
    ME22
    Use OKCODE = '/BDA' (in codes)at the start of ME22.
    Start the Session through SM35 in Back ground
    As you come to ME22-->Processing will come to foreground mode.
    Or-->
    Create a session.
    Sequence:
    ME51
    ME21--> '/BDE'(in codes)
    ME22
    Use OKCODE = '/BDA' (in codes)at the start of ME22.
    Start the Session through SM35 in Foreground ground
    As it comes to ME21 processing will be done in Backgrond(Unless error occurs or '/BDA')
    As you come to ME22-->Processing will come to foreground mode.
    Try it this works.
    Regards,
    Gurpreet

  • Background/Foreground Enhancement

    My photo has two grandgirls in foreground, standing in trees;
    background is too bright.
    I know there is a way of auto adjusting both back and fore
    grounds, but can't remember how to address or access.
    Still a novice here. . . .

    In order to enhance the foreground and background independently, I utilize the following technique:
    Duplicate background layer, work on background copy layer, shut off visibility of background layer
    Select foreground area with one of the selection tools, e.g. lasso, feather 5-15 px
    Create levels adjustment layer #1
    Press CTRL + click on the white rectangle in adjustment layer #1
    Select original image in background copy layer
    Go to Select>inverse
    Create levels adjustment layer #2
    Double click the the box on the left in the adjustment layer (one at a time) to access the levels controls, and work the sliders beneath the histogram.

  • Background/ForeGround jobs -- Identify?

    Hi ,
    We ran some jobs from BI to extract data from SRM.
    How to identify whether it is a background job  or Foreground Job?
    Please let me know step wise.. What Tcodes shall I use in both systems...
    Thanks in advance.
    Cheers,
    S

    Hi,
    Thanks for the reply. 
    Here is my question again:
    In BI: Info package is executed in BI (with start data load immediate  option ) - which means that the job is running in foreground in BI.
    In source system: Is this running in foreground/background?
                               I can view the job in SM37 in source system. 
                              Does that mean  the job is running in background in SOURCE 
                              system also?
    Hope I'm clear with my question.
    Cheers
    S

  • Can't render background color in JComboBox, after selection.

    I don't understand why this problem is so difficult. It is driving me nuts.
    If I create a renderer for a Jcombobox, it will correctly render TEXT and COLOR if it is displaying it in the pop up list, but as soon as it has been selected, the combo will render TEXT correctly but will ignore COLOR. I have tried playing around with opacity and with the editors, but it just seems as if JComboBox renderers do not work 100% as expected.
    Here is my text code. All I want is for the color of X or Y to be reflected in the selected element :
    import java.awt.BorderLayout;
    import java.awt.Color;
    import java.awt.Component;
    import javax.swing.DefaultListCellRenderer;
    import javax.swing.JComboBox;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JList;
    import javax.swing.JPanel;
    public class CustomComboBoxDemo extends JPanel {
        public CustomComboBoxDemo() {
            super(new BorderLayout());
            String[] s = { "1", "2", "3", "4", "5" };
            JComboBox c = new JComboBox(s);
            JComboBox c2 = new JComboBox(s);
            c.setOpaque(true);
            ComboBoxRenderer renderer= new ComboBoxRenderer();
            c.setRenderer(renderer);
            c2.setRenderer(renderer);
            JPanel p = new JPanel();
            p.add(c);
            p.add(c2);
            add(p);
        class ComboBoxRenderer extends DefaultListCellRenderer {
            public ComboBoxRenderer() {
                setOpaque(true);
            public Component getListCellRendererComponent(
                                               JList list,
                                               Object value,
                                               int index,
                                               boolean isSelected,
                                               boolean cellHasFocus) {
                 JLabel c = (JLabel)super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
                 if (value.toString().equals("3")) {
                     c.setText("X");
                     c.setBackground(Color.RED);
                 } else {
                     c.setText("Y");
                     c.setBackground(Color.GREEN);
                 return this;
        public static void main(String[] args) {
            javax.swing.SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    createAndShowGUI();
        private static void createAndShowGUI() {
            //Create and set up the window.
            JFrame frame = new JFrame("CustomComboBoxDemo");
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setContentPane(new CustomComboBoxDemo());
            //Display the window.
            frame.pack();
            frame.setVisible(true);
    }

    I think the problem has to do with the Alloy look and feel. If I use the Systsem look and feel then the setBackground() method does not colour in the button (just the textfield)
    This has fixed my initial problem :
    import java.awt.BorderLayout;
    import java.awt.Color;
    import java.awt.Component;
    import javax.swing.DefaultListCellRenderer;
    import javax.swing.JComboBox;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JList;
    import javax.swing.JPanel;
    import javax.swing.UIManager;
    import javax.swing.plaf.basic.BasicComboBoxEditor;
    public class CustomComboBoxDemo extends JPanel {
        public CustomComboBoxDemo() {
            super(new BorderLayout());
              try {
                   UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
              } catch (Exception e) {
                   e.printStackTrace();
            String[] s = { "1", "2", "3", "4", "5" };
            JComboBox c = new JComboBox(s);
            JComboBox c2 = new JComboBox(s);
    //        c.setRenderer(aRenderer)
    //        c.getEditor().getEditorComponent().setBackground(Color.GREEN);
            c.setBackground(Color.pink);
            c2.setBackground(Color.pink);
    //        c2.setBackground(Color.black);
            c.setOpaque(true);
            c2.setOpaque(false);
            ComboBoxRenderer renderer= new ComboBoxRenderer();
            c.setRenderer(renderer);
            c2.setRenderer(renderer);
            JPanel p = new JPanel();
            p.add(c);
            p.add(c2);
            add(p);
        private class MyComboBoxEditor extends BasicComboBoxEditor{
             public Component getEditorComponent(){
                  Component comp = super.getEditorComponent();
                  comp.setBackground(Color.red);
                  return comp;
        class ComboBoxRenderer extends DefaultListCellRenderer {
            public ComboBoxRenderer() {
                setOpaque(true);
            public Component getListCellRendererComponent(
                                               JList list,
                                               Object value,
                                               int index,
                                               boolean isSelected,
                                               boolean cellHasFocus) {
                 JLabel c = (JLabel)super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
    //             setForeground(Color.green);
    //             setBackground(Color.black);
    //             list.setForeground(Color.green);
    //             list.setBackground(Color.black);
                 if (value.toString().equals("3")) {
                     c.setText("X");
                     c.setBackground(Color.RED);
                 } else {
                     c.setText("Y");
                     c.setBackground(Color.GREEN);
                 return this;
        public static void main(String[] args) {
            javax.swing.SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    createAndShowGUI();
        private static void createAndShowGUI() {
            //Create and set up the window.
            JFrame frame = new JFrame("CustomComboBoxDemo");
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setContentPane(new CustomComboBoxDemo());
            //Display the window.
            frame.pack();
            frame.setVisible(true);
    }

  • Background color of JComboBox when disabled

    Hi,
    I wish to know how to retain the back ground color of a JCombo Box when it is in disabled state ?
    Regards
    Lucky

    something like setBackground(Color.WHITE)

  • Error message when trying to change Foreground/Background color

    Just in case anyone is having this problem in Photoshop CC where when you try to change/exchange or set to default the Background/Foreground colors and you get an error message of something like "Could not complete because of program error". I found the cure for this in an archive from when CS6 was in beta testing. Basically you have to delete the preferences file and restart the program. Here's a link to the article  http://forums.adobe.com/message/4336237. Apparently this "beta" problem can still occur as I am using the most recent version  of Photoshop CC.

    If you are trying to change the settings of your Router using the LELA software, and if you are getting an error message "Unable to Save the Data" its better you can exit from the LELA software and change all the Configuration settings on your Router Manaully.
    Open an Internet Explorer browser page on your wired computer(desktop).In the address bar type - 192.168.1.1 and press Enter...Leave Username blank & in Password use admin in lower case...
    For Wireless Settings,  Click on the Wireless tab
    Below you can make the changes on your Router ( SSID, Channel and let the SSID Broadcast should be Enable) and click on Save Settings... 
    For Wireless Security : -
    Click on the Sub tab under Wireless > Wireless Security...
    Change the security Mode to WPA Personal and under Passpharase type in your Security password and click on Save Settings.. 
    Once done, Now on your computer try to connect to your Wireless Network. Once connected you should be Online from your Computer. 

Maybe you are looking for

  • Re: How do I file a complaint to Best Buy?

    I need help!!!!!!!!!!!!!!!!!!!!!1 How do I start?? Simple is best! #geedsquad #bestbuy Geeksquad Service Protection Plan #{removed per forum guidelines} 10/23/14 - Started process for broken device at the Best Buy in Garner, NC - After NOT RECEIVING

  • Stock transport orders within one plant

    Hi all, I am wondering how to process a stock transport order, that is created to transfer stock within one plant (from one stor.loc to another). My general scope is to use the shipping module to process the logistic part of that transaction. So I cr

  • Integration to facebook for my ios app

    Hello folks, I am trying to build a new ios app on xcode and i have a doubt of how to integrate iphone's internal facebook app to my app so that it prompts me to use the internal facebook allow facebook to use your app. Thanks in advance

  • Debugging Code without NI-DAQ I/O Board

    Hello! I am developing in Delphi a simple application that read analog data from an AT-MIO-16XE-10. I would like to develop without the I/O Board installed on my computer... is it possible? thanks in advance! filippo

  • How to Navigate from af:internalFrame to another page in the parent frame?

    Hi! I'm using an ADF IFrame Component <af:internalFrame>.. we have a requirement where we needed to navigate from a page in the Internal frame to another page in the browser, i.e., on clicking a ceratain button in IFrame , the browser window should l