JButton setBackgroundColor doesn't work with Windows XP Look and Feel

Posted on 2004-11-02
Last Modified: 2013-11-23
My swing application uses JButtons with different background colours. In my application the colour conveys important information and is necessary.

When the code runs under Windows 2000, it works fine, but as soon as it runs under XP, all the buttons appear the same colour under the new XP Look and Feel. The setBackgroundColour function does nothing.

I've tried running some code I found on the Java website as a work-aroung, but it doesn't support HTML on the buttons (which I also require).

The code I tried I found here:

Anyone else have any suggestions?
Question by:peparsons
    LVL 9

    Expert Comment

    Have you tried changing the look and feel to one, other than Windows? (or must it be windows?)


    Author Comment

    It would work with any of the other standard java look and feels, but I'm looking to write a Windows application, with the standard windows look and feel. Alos, the end users will be using both Windows 2000 and XP.
    LVL 3

    Expert Comment



    Can you paste the relevant code portions?

    I have used the .setBackgroundColor in my application and it worked for XP clients, thats why I am asking...

    LVL 3

    Expert Comment


    Oh, also note that I used J2SE 5.0, I'll try to run it with J2SE 1.4.2 (that I noticed this is what you used, in the thread you supplied).

    LVL 37

    Expert Comment

    You could try jGoodies Looks (

    I quote:

    :: JGoodies Windows L&F :: Precise Emulation ::
    The JGoodies Windows look&feel focuses on a precise emulation on Windows 95/98/NT/ME/2000 in the following areas: menus, icons, colors, borders, fonts, font sizes, insets, and widget dimensions. It honors the screen resolution (96dpi vs. 120 dpi) to adjust sizes, insets, and widget dimensions.
    LVL 15

    Expert Comment


    That would be the problem of windows xp. Since the default look and feel of windows looks like metal its not available to do it in Java.
    we can change it if we change the settings of windows xp's apperance to classic but w/o changing it to classic there's no other way.
    Unless you make your own customize look and feel for Java.
    LVL 15

    Expert Comment

    I hope my solution did not give you a headache but I would say that it is the fact.
    LVL 92

    Expert Comment

    Using images for your buttons will give you full control over there appearance.
    LVL 15

    Accepted Solution

    However you can still tweak the look and feel of the button by customizing the whole button its self.
    You can create your own graphics and use it as the button.

    1. Customize your buttons by designing the image.
    2. Use the codes bellow for customizing it :

      JButton button = new JButton(new ImageIcon("x1.gif"));
      button.setPressedIcon(new ImageIcon("x2.gif"));
      button.setRolloverIcon(new ImageIcon("x3.gif"));
      button.setDisabledIcon(new ImageIcon("x1.gif"));
      button.setMargin(new Insets(0,0,0,0));

    Hope that helps . . .

    LVL 24

    Expert Comment

    I'm afraid the simplest solution is to put a coloured image (with text) on your button(s).
    If you want to mark (e.g.) a RED button, that's surely the way to go.


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Course: From Zero to Hero with Nodejs & MongoDB

    Interested in Node.js, but don't know where to start or how to learn it properly? Confused about how the MEAN stack pieces of MongoDB, Expressjs, Angularjs, and Nodejs fit together? Or how it's even possible to run JavaScript outside of the browser?

    Suggested Solutions

    Title # Comments Views Activity
    FizzBuzz challenge 9 51
    hasOne  challenge 59 46
    matchUp  challenge 9 33
    SPLUNK REST  API call to Splunk to create and index? 2 12
    In our object-oriented world the class is a minimal unit, a brick for constructing our applications. It is an abstraction and we know well how to use it. In well-designed software we are not usually interested in knowing how objects look in memory. …
    This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
    Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
    This video teaches viewers about errors in exception handling.

    913 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    12 Experts available now in Live!

    Get 1:1 Help Now