Good day. Tell me, how can I round the edges of the button?
1 answer
Create a RoundedBorder class:
public class RoundedBorder implements Border { private int radius; RoundedBorder(int radius) { this.radius = radius; } public Insets getBorderInsets(Component c) { return new Insets(this.radius+1, this.radius+1, this.radius+2, this.radius); } public boolean isBorderOpaque() { return true; } public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) { g.drawRoundRect(x, y, width-1, height-1, radius, radius); } } Install the custom border button:
button.setBorder(new RoundedBorder(10)); Taken from here .
- 1) When using this method, if we set the background color, the element is still highlighted by a square. 2) This method does not make the button completely round, because in this case, the text turns into some kind of squares. (The button is large, and there is a lot of space for text. I tried to change the font size - it did not help) Is there any ... standard CSS-like method "border-radius"? Or is everything done only with such crutches? - TrueASL
- @TrueASL, I did not find the standard method. By the way, in JavaFX styles can be set directly using CSS. - post_zeew
|