Home java how to make round corners from JButton with color background'a in java

how to make round corners from JButton with color background’a in java




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 () {
  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);
  Public Insets GetBorderinsets (Component C) {
    RETURN NEW INSETS (13 + 1, 13 + 1, 13 + 2, 13);
  Public Boolean IsborderOpaque () {

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);
    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);
    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.

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions