Reputation: 851
For my assignment I need a 2 dimensional array of JButtons in a grid JPanel in a JFrame. The JButtons must change color when clicked. I cannot get them to hold any color.
I implemented the solutions proposed in a previous thread and found that the work around only produced border color:
JButton button = new JButton("test");
button.setBackground(Color.RED);
button.setOpaque(true);
unpainting the border:
button.setBorderPainted(false);
simply causes the entire JFrame to be red.
This issue is only with MAC computers and not the intended problem of the assignment.
Any thoughts?
Upvotes: 2
Views: 2652
Reputation: 17650
Remember : The Swing toolkit is pretty good at getting the system look and feel "almost right". If you really need the system feel, however, there are other options like SWT that are a little better suited.
If you want consistency then Swing can always default to the old school applet look which, although a little boring, is pretty reliable . The upside of this is that, when we roll back to this more simplistic looking gui toolkit, platform specific quirks magically seem to disappear .
I think you might find your problem solved quite easily if you simply set the look and feel to the standard swing style look and feel.
The Solution
I would suggest a call to
UIManager.setLookAndFeel(
UIManager.getCrossPlatformLookAndFeelClassName());
In the static code block where you initialize your application.
Upvotes: 5