I use JButtons in my application. They need to have different colors. First I used that btn.setBackground(col);. It works on my computer and on another computer my button just gray (not red, as it’s supposed to be).
Trying to solve this problem I decided to use images. I do it in the following way: tmp = new JButton(newIcon);
Again, it works fine on my computer and on another computer I see just gray buttons.
Does anybody have any ideas what can be the reason of the problem and how it can be solved? I heard it can be related to “look-and-feel of the native system”. But I do not know what it means and what should I do if it is the case? Can anybody pleas, help me with that?
Swing has the concept of pluggable look and feels. Some of those look and feels mimic the look of native components from Windows, GTK+, etc. Even on Windows there are two separate look and feels – Classic and Vista I think. Maybe you’re using different OSes on your two systems and an GUI designer that sets the look and feels automatically. Most don’t however – the default look and feel Metal(before Java 1.6.10) and Nimbus look the same on every OS.
The first part of the code build a list of the available look and feel names and the second acts upon one of them being selected. But since you want always to use the same laf you can use something like: