Thanh Nguyen
Thanh Nguyen

Reputation: 81

Set the length of border (jbutton) in Java

I have the button in Java (which includes text and icon), but with the default border, the border (the retangle outside the text and icon) is rather long, so how could I set the customed border (width, length) of jbutton. So far, i tried

button.setSize(x, y);

but it doesn't work.

Thanks.

Upvotes: 4

Views: 4124

Answers (2)

jonathan
jonathan

Reputation: 1

    setLayout(null);
    setPreferredSize(new Dimension(950, 550));

that worked for me just change the Dimensions to your liking...goodluck hope it works! just noticed the date. sorry for gravedigging maybe it'll help someone else though lol

Upvotes: 0

Dennis
Dennis

Reputation: 1101

I might get the problem wrong, but you can set the border of a JButton like this:

Border border = new LineBorder(Color.WHITE, 12);
JButton button = new JButton("12 Pixel");

button.setBorder(border);

You might want to have a look at the documentation of LineBorder.

Upvotes: 3

Related Questions