Good afternoon all. There is an application on swing. The application has a panel with buttons. Task: All buttons need to round the corners. It is desirable that this was done through Uimanager. Also, it is worth considering that the buttons are set to the background color and color when the button is squeezed. I tried to do so, but then the background color goes beyond the corners:
button.setborder (new border () {
@Override
Public Void Paintborder (Component C, Graphics G, Int X, Int Y, Int Width, Int Height) {
g.drawroundrect (x, y, width - 1, height - 1, 13, 13);
}
@Override
Public Insets GetBorderinsets (Component C) {
RETURN NEW INSETS (13 + 1, 13 + 1, 13 + 2, 13);
}
@Override
Public Boolean IsborderOpaque () {
RETURN FALSE;
}
});
I’m in a dead end)
Answer 1, Authority 100%
class circlebtn extends jbutton {
Public Circlebtn (String Text) {
Super (text);
Dimension Size = GetPreferredSize ();
size.width = size.Height = Math.max (size.width, size.height);
SetPreferredSize (Size);
SetContentArafilled (False);
}
@Override
PROTECTED VOID PAINTCOMPONENT (Graphics G) {
if (getModel (). Isarmed ()) {
g.setcolor (Color.green); // Background color when the button is pressed
SetForeGround (Color.yellow); // Absorption color when the button is pressed
} else {
g.setcolor (getBackground ()); // Color Background
SetForeGround (Color.Black); // Color lettering
}
g.fillroundRect (0, 0, GETSIZE (). width - 1, getsize (). Height - 1, 13, 13);
super.paincomponent (G);
}
@Override
PROTECTED VOID PAINTBORDER (Graphics G) {
g.setcolor (getForeground ());
G.DrawroundRect (0, 0, GETSIZE (). width - 1, getsize (). Height - 1, 13,13);
}
}
class inherited from Jbutton. Overdid in it methods of drawing the form of the PaintBorder button and the method of drawing internal elements PaintComponent.