Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Set the Background Color of a JButton on the Mac OS

Tags:

java

macos

swing

Normally with Java Swing you can set the background color of a button with:

myJButton.setBackground(Color.RED); 

which would cause the button to be red. But on the Mac OS, this method seems to be ignored. The button just stays the default color.

How can the color of a JButton be set on the Mac OS?

like image 571
Stephane Grenier Avatar asked Jun 30 '09 19:06

Stephane Grenier


People also ask

How do you color a button in Java?

Use the setBackground method to set the background and setForeground to change the colour of your text.

How do I change the shape of a Jbutton in Java?

You can use customize your button by adding a border which will change its shape such as rounded or circular..the following code creates a rounded border..you can draw a circle to get a circular button class RoundedBorder extends AbstractBorder { public void paintBorder(Component c, Graphics g, int x, int y, int width, ...


1 Answers

Have you tried setting JButton.setOpaque(true)?

JButton button = new JButton("test"); button.setBackground(Color.RED); button.setOpaque(true); 
like image 171
codethulhu Avatar answered Sep 23 '22 04:09

codethulhu