Getting incorrect JComboBox color through UIManager in Nimbus Look&Feel

Hello all,
As I implementing a multi columns JComboBox, I need to provide my own custom ListCellRenderer.
* @author yccheok
public class ResultSetCellRenderer extends javax.swing.JPanel implements ListCellRenderer {
    // Do not use static, so that our on-the-fly look n feel change will work.
    private final Color cfc  = UIManager.getColor("ComboBox.foreground");
    private final Color cbc  = UIManager.getColor("ComboBox.background");
    private final Color csfc = UIManager.getColor("ComboBox.selectionForeground");
    private final Color csbc = UIManager.getColor("ComboBox.selectionBackground");
    private final Color cdfc = UIManager.getColor("ComboBox.disabledForeground");
    @Override
    public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
        System.out.println("UIManager.getColor(ComboBox.selectionForeground) = " + UIManager.getColor("ComboBox.selectionForeground"));
        System.out.println("UIManager.getColor(ComboBox.selectionBackground) = " + UIManager.getColor("ComboBox.selectionBackground"));
        this.setBackground(isSelected ? csbc : cbc);
     this.setForeground(isSelected ? csfc : cfc);
        jLabel1.setBackground(isSelected ? csbc : cbc);
     jLabel1.setForeground(isSelected ? csfc : cfc);
        jLabel2.setBackground(isSelected ? csbc : cbc);
     jLabel2.setForeground(isSelected ? csfc : cfc);
        jLabel3.setBackground(isSelected ? csbc : cbc);
     jLabel3.setForeground(cdfc);
        final ResultType result = (ResultType)value;
        jLabel1.setText(result.symbol);
        jLabel2.setText(result.name);
        final String type = result.typeDisp != null ? result.typeDisp : result.type;
        final String exch = result.exchDisp != null ? result.exchDisp : result.exch;
        jLabel3.setText(type  + " - " + exch);
        return this;
}I try to get the selection colors of JComboBox through UIManager.
    private final Color csfc = UIManager.getColor("ComboBox.selectionForeground");
    private final Color csbc = UIManager.getColor("ComboBox.selectionBackground");However, I realize that while I am in Nimbus Look & Feel, the above 2 return me null.
May I know is there any workaround to overcome this? Or I had missed out something?
Thanks.
Edited by: yccheok on Oct 21, 2010 10:39 AM

because "c" is instance of UIResource:
import java.awt.*;
import javax.swing.*;
import javax.swing.plaf.*;
public class NimbusComponentColorTest {
  public JComponent makeUI() {
    final Color c = UIManager.getColor(
        "ComboBox:\"ComboBox.renderer\"[Selected].background");
    System.out.format("c instanceof UIResource: %s", c instanceof UIResource);
    JLabel label01 = new JLabel("label01");
    /* //com/sun/java/swing/plaf/nimbus/AbstractRegionPainter.java
    protected final Color getComponentColor(...) {
      // we return the defaultColor if the color found is null, or if
      // it is a UIResource. This is done because the color for the
      // ENABLED state is set on the component, but you don't want to use
      // that color for the over state. So we only respect the color
      // specified for the property if it was set by the user, as opposed
      // to set by us.
      if (color == null || color instanceof UIResource) {
          return defaultColor;
      } else if(saturationOffset!=0||brightnessOffset!=0||alphaOffset!=0) {
    label01.setOpaque(true);
    label01.setBackground(c);
    JLabel label02 = new JLabel("label02");
    label02.setOpaque(true);
    label02.setUI(new javax.swing.plaf.metal.MetalLabelUI());
    label02.setBackground(c);
    JLabel label03 = new JLabel("label03") {
      @Override public void paintComponent(Graphics g) {
        g.setColor(c);
        g.fillRect(0,0,getWidth(),getHeight());
        super.paintComponent(g);
    JLabel label04 = new JLabel("label04");
    label04.setOpaque(true);
    label04.setBackground(new ColorUIResource(Color.RED));
    JPanel p = new JPanel();
    p.add(label01); p.add(label02); p.add(label03); p.add(label04);
    return p;
  public static void main(String[] args) {
    EventQueue.invokeLater(new Runnable() {
      @Override public void run() { createAndShowGUI(); }
  public static void createAndShowGUI() {
    try {
      for (UIManager.LookAndFeelInfo laf:UIManager.getInstalledLookAndFeels())
        if ("Nimbus".equals(laf.getName()))
          UIManager.setLookAndFeel(laf.getClassName());
    } catch (Exception e) {
      e.printStackTrace();
    JFrame f = new JFrame();
    f.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    f.getContentPane().add(new NimbusComponentColorTest().makeUI());
    f.setSize(200, 100);
    f.setLocationRelativeTo(null);
    f.setVisible(true);
}

Similar Messages

  • OHJ show blank topic window with Nimbus Look & Feel

    Hi,
    I am using Oracle Help for Java. When I switch to Nimbus Look & Feel the topic window is blank - it does not display topic information. When I click button <Print> in topic window the topic is printed correctly. The same help work properly in other Look & Feels.

    The application that demonstrates this problem is jEdit - an open source text editor. I was told that the development of this editor started before JScrollPane was added to the JRE. Currently there's a lot of code, with high complexity, that replaces the JScrollPane for the text component of the editor, and I wouldn't go change it now. But leave that aside - I am particularly interested to know if this behavior is a bug in Nimbus or maybe my understanding of it is incorrect.
    In any case I don't want to hide the casing of the scrollbar, just the scrollbar (thumb) inside the casing. Isn't it strange that without modifying the value or limits, the scrollbar suddenly appears when the view becomes wider? It should be the other way around, the scrollbar should become visible when the view becomes narrower than the contents.

  • Can I get a different color iPhone if I order a replacement through insurance?

    Can I get a different color iPhone if I order a replacement through insurance?

        hoseykel,
    Thank you for reaching out to us. We are more then happy to assist with this question. When getting the device replaced through insurance, the replacement calls for the same make and model, which includes color. Now if they are not in stock of the same color then they will offer a different color, but normally only in that situation. Let us know if you have any other questions.
    Thank you,
    Tony_VZW
    Please follow us on twitter @VZWSupport

  • JComboBox color problem

    Problem:
    Setting the button background color via UIManager.put(....) actually changes part of the background of my comboboxes. I also set the combobox background with UIManager, but it only applys this color where the data is within the combobox. The area where the down arrow is (on the combobox) is the color that I set the buttons to.
    Question:
    Is there a way to prevent this line:
    UIManager.put("Button.background", ButtonColor);
    from affecting my combobox background?
    I want to achieve custom user colors for the various components within the application, but I want to set these colors in one location, through UIManager.put(...).

    Try storing a custom Object in the model, not a text string. The object would contain the text, foreground and background color. Then the renderer simply gets the value to be rendered, casts it to your Object type and retrieves the 3 pieces of information which it uses to set the text, background and foreground. No need for if / else statements. Here is a simple example:
    http://forum.java.sun.com/thread.jspa?forumID=57&threadID=613731

  • Can I get back the color control bar?

    After a 5 hour download and install, the most noticeable change is that Apple changed the left-hand side control bar from colored to all gray. 
    Frankly, I've been very disappointed with Apple's design changes lately, and this one is another example, although, I love the new translucent trash can.  I've figured out work-arounds to many of the changes I find most offensive (e.g. my folders are no longer Yosemite-native neon blue.) 
    Is there a way to get back the colors on the left-hand side control bar in iPhoto? 
    I don't mind digging through hidden folders and re-building the icons so that my interface looks good again.  Any suggestions are appreciated.

    If you want to restore the color to the Finder's sidebar give the open source application cDock a try.  You can change the Dock's background scheme (I use transparent) and add color icons to the Finder's sidebar:

  • How do you get an exact color match?

    I can paint the bumper of this car but I get a flat color instead of the shine that normally comes with a car, how do you do this?

    I would use the Paintbucket Tool.
    Here is a step through:
    Auto on Background Layer.
    Create Selection (about what you have shown for that area, but I'd make it just a bit larger), and Save Selection.
    Take Color Sample from a similar area.
    Save to Swatches Panel, in case you need it again.
    Create New Layer, above Background Layer.
    Load Selection.
    Use Paint Bucket.
    Save Selection as Layer 1 Layer Mask for later.
    Change Blending Mode in Layer 1 to Color.
    Make the Layer 1 Layer Mask Channel active in Channels Palette.
    The colors will now switch to black and white, so you can paint in, or out that Layer Mask, and can use the Blur Tool, or a Filter, like Gaussian Blur to soften the edges.
    If necessary, you can add a Levels Adjustment Layer to Layer 1, and alter things a bit.
    Hope that helps, and that I have not forgotten a step. In the US, on Memorial Day, I have declared Wine-thirty early...
    Good luck,
    Hunt

  • Getting incorrect coordinates, width/height of page-item in actionscript.

    Hi,
    I am developing a Flex extension for InDesign CS5. I am trying to get the coordinates and width/height of a page-item. But, I keep getting incorrect data. Please refer screenshot. The coordinates as I see in the InDesign application are 38.8, 66.02, 117.5, 160.5.
    I used the geometricBounds method to get the coordinates and width/height, but I am getting 29.70, 40.26, 222.07, 178.11. Please refer the screenshot.
    I read somewhere that the coordinates can change with respect to the ruler settings, i.e., it depends on Ruler per Spread, Ruler per Page or Ruler on Spine. But, I couldn't find anything related to this with respect to actionscript.
    How can I get the coordinates and width/height that I see in the InDesign application through actionscript?
    Thanks!

    @poortip87 – make a rectangle with the coordinates ActionScript is suggesting on your page together with your placed image. Then you can see how this correlates to the path points of the rectangle that holds the image.
    Further reading on geometricBounds and their relationship to other geometric properties of page items can be found here:
    Marc Autret:
    Work Around the Width/Height Gap
    http://www.indiscripts.com/post/2009/10/work-around-the-width-height-gap
    Uwe

  • Performance is very slow, i continue to get the spinning color wheel whenever i try anything (email, browser, word, etc)  any ideas

    Performance is very slow.
    I continue to get the spinning color wheel on whatever I try.
    It doesnt matter if its an email, browser or document of any kind it takes several seconds for anything to happen.

    Hello, see how many of these you can answer...
    See if the Disk is issuing any S.M.A.R.T errors in Disk Utility...
    http://support.apple.com/kb/PH7029
    Open Activity Monitor in Applications>Utilities, select All Processes & sort on CPU%, any indications there?
    How much RAM & free space do you have also, click on the Memory & Disk Usage Tabs.
    Open Console in Utilities & see if there are any clues or repeating messages when this happens.
    In the Memory tab, are there a lot of Pageouts?

  • When I check my boot SSD drive using Disk Utility under Mavericks, I often get "Incorrect number of extended attributes" errors.  But if I boot off an external drive and check the same SSD, no errors are reported.  Is this a bug in Mavericks?

    When I check my boot SSD drive using Disk Utility under Mavericks, I often get "Incorrect number of extended attributes" errors.  But if I boot off an external drive and check the same SSD, no errors are reported. 
    This happens not just with the SSD in my Mac Mini, but with another SSD in my MacBook (both now running Mavericks).  So far as I know, all of the kit I am using is in good order (despite the file corruption reports).  So I am beginning to wonder if it could be due to a bug in Mavericks?  Both SSD drives have been formatted to MacOS Extended (journaled) format.  Should I have used a different format, I wonder?
    Has anyone else encountered this issue?
    Does anyone have a solution?
    Or an explanation that might help my investigation of the issue?
    Thanks guys,

    I understand that the Corsair Force 3 is not one of the SSD drives that are supported on Apple Macs. 
    I did try downloading and using Trim Enabler, but the error message came up both when it was off and when it was on.
    I understand that not everyone thinks Trim Enabler is a good program, though there is a new version out now, so I may give it another try.

  • I recently purchased a book from itunes on my ipad 2 but when i open the book in ibooks i get (incorrectly formatted or not formatted for ibooks) somebody please help

    I am currently deployed over seas.. I recently purchased a book that im pretty stoked about. but when i open it in ibooks i get ( incorrectly formatted or not formatted for ibooks to recognize) the file is an .epub so i dont see how it could be a format issue.. I tried emailing apple but because of the situation they want me to call. I have very limited telecomminications at my location .. somebody please help

    The Report a Problem link can also be found in iTunes/Store/View Account/Purchase History.
    Before asking for a refund, also try deleting the book and redownloading it.
    If you find that the iBookstore is does not meet your needs, you can try one of the others like Kindle, Nook, Kobo, Googlebooks, or Sony.
    To let Apple know your views on their apps or services, use
    http://www.apple.com/feedback

  • How to get the reverse color of a color

    how to get the reverse color of a color
    thanks

    int red = Math.abs(255 - oldColor.getRed());
    int green = Math.abs(255 - oldColor.getGreen());
    int blue = Math.abs(255 - oldColor.getBlue());
    java.awt.Color inverseColor = new java.awt.Color(red, green, blue);
    Where oldColor is a java.awt.Color object.
    Hope this is want u need !!!

  • I am having trouble connecting MacBook Pro (10.6.7) to Novell server. I get incorrect username and password message. I can connect worksations running 10.5 without any problem. Any possible solution? Thanks, Ned

    I am having trouble connecting MacBook Pro (10.6.7) to Novell server. I get incorrect username and password message. I can connect worksations running 10.5 without any problem. Any possible solution? Thanks, Ned

    Having the exact same problem with connecting ML and Snow Leopard machines to a Windows 8.1 machine. Oddly enough, connecting and copying to/from works perfectly from a Mavericks machine, despite the problems reported about Mavericks regarding the exact opposite. An old thread, but did you find a solution?

  • On my G5 mac at work, I am getting - don't know what to call it - looks like extraneous matrix type code around prompt windows and in applications. Sometimes I will get large shapes of colors, yellows, magentas, cyans. Anyone else experience this?

    On my G5 mac at work, I am getting - don't know what to call it - looks like extraneous matrix type code around prompt windows and in applications. Sometimes I will get large shapes of colors, yellows, magentas, cyans. Anyone else experience this?
    I will attach a recent screen shot of a print window I opened and the extra code is above and below the window. There are matrix type blocks of code and then lines under the window. I get this all the time and it is getting worse.
    Any help to get rid of it would be appreciated.
    Thanks
    TatteredSkull

    It's likely the Video card, or possibly heat.
    At the Apple Icon at top left>About this Mac.
    Then click on More Info>Hardware and report this upto *but not including the Serial#*...
    Hardware Overview:
    Machine Name: Power Mac G5 Quad
    Machine Model: PowerMac11,2
    CPU Type: PowerPC G5 (1.1)
    Number Of CPUs: 4
    CPU Speed: 2.5 GHz
    L2 Cache (per CPU): 1 MB
    Memory: 10 GB
    Bus Speed: 1.25 GHz
    Boot ROM Version: 5.2.7f1
    Get Temperature Monitor to see if it's heat related...
    http://www.macupdate.com/info.php/id/12381/temperature-monitor
    iStat Menus...
    http://bjango.com/mac/istatmenus/
    And/or iStat Pro...
    http://www.islayer.com/apps/istatpro/
    If you have any temps in the 70°C/160°F range, that's likely it.

  • How to get audio to play through TV?

    I have a Thunderbolt to HDMI cable and can only get video to show up on my HDTV screen. I am trying to get audio to play through the TV as well, but it only plays through my Macbook Pro. Any suggestions?

    Hi ajlarson6,
    I found some information concerning the settings that need to be in place to play audio through a TV:
    OS X Mountain Lion: Use a television as a display
    http://support.apple.com/kb/PH10671
    I hope this helps!
    - Ari

  • My 24" iMac seems to gets the spinning colored ball a lot, seems it is running slow a lot more than it did before any suggestion?

    My 24” iMac seems to gets the spinning colored ball a lot, seems it is running slow a lot more than it did before any suggestion?

    Open Activity Monitor in Applications>Utilities, select All Processes & sort on CPU%, any indications there?
    How much RAM & free space do you have also, click on the Memory & Disk Usage Tabs.
    In the Memory tab, are there a lot of Pageouts?

Maybe you are looking for

  • Podcast App 1.1.1 (185) and iTunes Sync

    Hi, I wonder if someone can point me to the correct why to use this application with iTunes, the issues I seem to be having is i have deleted the appliction off the iphone and to try and get the list of podcasts back to the same as the PC. Do i now s

  • Dependant values in a pl/sql html portlet

    I have a simple html form that shows records to be updated with a submit button. One of the field shows multiple cycles from a table with radiobutton. Different amounts have to be shown for different values of cycles. This amount should be dynamicall

  • Blackberry bridge folder and all icons can no longer be found

    I have my blackberry connected to my 9780 thru BB Bridge. The Bridge folder and its icons can not be found, however. I know that I'm connected (the number of bridge messages are showing up in the upper left corner of the screen, but no icons. Remote

  • Tips for working with USB floppy drives

    I was just wondering if anyone had any tips on working with USB floppy drives in Archlinux. One thing I've noticed is that trying to use mkfs.msdos on my USB floppy drive directly doesn't seem to result in a usable disk (it's mountable, but reports t

  • Corrupted Database Problem

    Greetings, I'm getting the following error running the base system installer: root@archiso ~ # pacstrap -i /mnt base ==> Creating install root at /mnt ==> Installing packages to /mnt error: GPGME error: No data :: Synchronizing package databases.. co