Reputation:
I want to change both the background and foreground color of my button. I used setBackground and setForeground and setOpaque(true), and it worked for the foreground, but not for the background of the button. There is kind of like a black border around the button, but I want the button itself to be black. How do I fix it?
this.closeButton = new JButton ("Close");
this.closeButton.setBackground(Color.BLACK);
this.closeButton.setForeground(Color.PINK);
this.closeButton.setOpaque(true);
Upvotes: 0
Views: 337
Reputation: 347332
The "border" is provided by the look and feel delegate. You can "disable" it by calling button.setBorderPainted
This may or may not meet your expecations
JButton button = new JButton("Close");
button.setBackground(Color.BLACK);
button.setForeground(Color.PINK);
button.setBorderPainted(false);
button.setOpaque(true);
Upvotes: 1
Reputation: 13
You can possibly do: this.closeButton.setTextColor(Color.PINK); uncomment line : this.closeButton.setForeground(Color.PINK) ;
Upvotes: 0