Here's the issue: When I try to add a border to a JButton via setBorder(), the normal background styling of the button:
disappears, to be replaced by what is essentially a clickable JLabel:
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
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.