I have a bug in my Swing program where the background of JButton and JToggleButton components is grey instead of blue, when the component is selected. Here is a screenshot of the issue on a JToggleButton, but the same issue occurs when pressing down on a JButton.
I have tried manually setting the background with
button.setBackground(Color.BLUE);
button.setOpaque(true);
but that just paints a small border around the button:
Also added button.setBorderPainted(false); which removes the border but also removes the macOS button look entirely + gives the text a darker background color:
It looks like the border (AquaButtonBorder) blocks the background color from changing or something? Because simply setting button.setBackground(Color.BLUE); does absolutely nothing.
The look and feel is set to UIManager.getSystemLookAndFeelClassName(), but also tried UIManager.getCrossPlatformLookAndFeelClassName() which was unsuccessful.
Java specifications: running on Java 11, but the same issue persists in Java 17
System specifications: M1 MacBook Pro, macOS version 12.4



Sooo, I spent WAY to much time digging into the source code for the "Aqua" look and feel, and I found that the
AquaButtonUIhas a "button type" client property which is used to (amongst a couple of other things) determine the border type.Sooo, I pulled all the internal "types" and did a quick test...
Generally, I found that
bevelandsegmented-onlywill achieve your desired result (althoughsegment-first/middle/lastlooks interesting)