Reputation: 41
Is there a way, if so how, to add a border to a button but only to the bottom of it? I want to change the colour of the bottom border of the button. Is it possible?
Upvotes: 2
Views: 2104
Reputation: 205875
A button's appearance is controlled by the UI delegate of the user's chosen Look & Feel. Borders applied directly to the button don't always appear. As suggested by the authors of setBorder()
, add the border proposed by @mprabhat to the button's surrounding container. Starting from this example, I made the following change to the ButtonPanel
constructor:
public ButtonPanel(int i) {
this.setBackground(new Color(rnd.nextInt()));
this.setBorder(new MatteBorder(0, 0, 2, 0, Color.RED));
this.add(new JButton("Button " + String.valueOf(i)));
}
Upvotes: 2