phoenixtu
phoenixtu

Reputation: 13

Adding Second Border to JButton

Here's the issue: When I try to add a border to a JButton via setBorder(), the normal background styling of the button:

correct

disappears, to be replaced by what is essentially a clickable JLabel:

incorrect

Basically, what I'd like to do is add a colored border around the current default border. If there's another process other than using setBorder() that would work, I would be interested in hearing about it.

Also, I should add that I cannot subclass or override methods of the graphics elements, as this needs to be inserted as a standalone tool in a far larger code repository.

Edit: Specifying question better

Upvotes: 0

Views: 256

Answers (1)

lordoku
lordoku

Reputation: 1122

You should create a compound border. You can do this:

JButton myButton = new JButton("BUTTON TEXT");
myButton.setBorder(BorderFactory.createCompoundBorder(myButton.getBorder(), BorderFactory.createLineBorder(Color.RED));

This will preserve the look/feel of the button and will add a red border.

Upvotes: 2

Related Questions