How to set the button color of a JButton (not background color)?

You'll have to decide if it's worth the effort, but you can always create youe own ButtonUI as shown in this example due to @mKorbel.

You'll have to decide if it's worth the effort, but you can always create youe own ButtonUI, as shown in this example due to @mKorbel.

I think that I will have to do this. Thank you for the link. – Joseph Trebbien Jun 6 at 21:01.

I use JDK 6 on XP. It looks like the Window UI doesn't follow the normal painting rules in more ways than 1. As you noticed setBackground() doesn't work.

You should be able to do custom painting by telling the component not to fill in the content area: import java.awt. *; import javax.swing. *; public class ButtonBackground extends JFrame { public ButtonBackground() { setLayout( new FlowLayout() ); JButton normal = new JButton("Normal"); add(normal); JButton test1 = new JButton("Test 1") { @Override public void paintComponent(Graphics g) { g.

SetColor( Color. GREEN ); g. FillRect(0, 0, getSize().

Width, getSize(). Height); super. PaintComponent(g); } }; test1.

SetContentAreaFilled(false); add(test1); } public static void main(String args) { try { // UIManager. SetLookAndFeel("com.sun.java.swing.plaf.windows. WindowsLookAndFeel"); } catch (Exception e2) {} ButtonBackground frame = new ButtonBackground(); frame.

SetDefaultCloseOperation( EXIT_ON_CLOSE ); frame.pack(); frame. SetLocationRelativeTo( null ); frame. SetVisible(true); } } When you run the code as is it seems to work properly.

That is when you click on the button you see the Border change. However is you run with the Windows XP LAF, the Border never changes to you don't see the button click effect. Therefore, I guess the issue is with the WindowUI and you would need to customize the UI which is probably too complex to do so I don't have a solution.

1 For reference, on Mac OS X, BackgroundButton looks like this when Test 1 is selected. – trashgod Jun 6 at 21:04.

But I still think that (modified but by Darryl) is correct UIManager. Get("Button. Gradient"), because would be crossplatform EDIT: correct answer would be - Nimbus or some Custom L&F, why reinvent the wheel (by Rob).

Displaying an Icon, making the button bold instead of plain text, etc. Indicating something only through a different background color isn't always obvious, and depending on the user's system colors, may be jarring, or invisible. For example, what if the user is running windows in "high contrast" mode?

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions