Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4380543

setMargin() does not work for AbstractButton

    Details

    • Subcomponent:
    • Resolved In Build:
      hopper
    • CPU:
      x86, sparc
    • OS:
      linux, solaris_7, windows_95, windows_98, windows_2000
    • Verification:
      Verified

      Description

      The setMargin() method works for the top, right, and bottom insets but for
      some reason does not work for the left inset. As demo with the following
      program the buttons/checkboxes always align to the left margin.

      ================================================================================
      import java.awt.*;
      import java.awt.event.*;
      import javax.swing.*;
      import javax.swing.event.*;

      public class rButton extends JFrame {

          rButton() {
      Container c = getContentPane();
      c.setLayout(new FlowLayout());

      JPanel p1 = new JPanel();
      JPanel p2 = new JPanel();
      p1.setLayout(new BoxLayout(p1, BoxLayout.X_AXIS));
      p2.setLayout(new BoxLayout(p2, BoxLayout.Y_AXIS));
      c.add(p1);
      c.add(p2);

              ImageIcon icon = new ImageIcon("./red-ball.gif");

              JRadioButton []rb1 = {
      new JRadioButton("Insets = 40", icon),
      new JRadioButton("Insets = 30"),
      new JRadioButton("Insets = 20"),
      new JRadioButton("Insets = 10")
      };

      JCheckBox cb1 = new JCheckBox("Insets = 15", icon);
      JCheckBox cb2 = new JCheckBox("Insets = 15", icon);
      cb1.setMargin(new Insets(15, 15, 15, 15));
      cb2.setMargin(new Insets(15, 15, 15, 15));

      rb1[0].setMargin(new Insets(10, 10, 10, 10));
      rb1[1].setMargin(new Insets(20, 20, 20, 20));
      rb1[2].setMargin(new Insets(30, 30, 30, 30));
      rb1[3].setMargin(new Insets(40, 40, 40, 40));

              JRadioButton []rb2 = {
      new JRadioButton("Insets = 40", icon),
      new JRadioButton("Insets = 30"),
      new JRadioButton("Insets = 20"),
      new JRadioButton("Insets = 10")
      };

      rb2[0].setMargin(new Insets(10, 10, 10, 10));
      rb2[1].setMargin(new Insets(20, 20, 20, 20));
      rb2[2].setMargin(new Insets(30, 30, 30, 30));
      rb2[3].setMargin(new Insets(40, 40, 40, 40));

      for (int i = 0; i < 4; i++) {
      p1.add(rb1[i]);
      p2.add(rb2[i]);
      }

      p1.add(cb1);
      p2.add(cb2);

      p1.validate();
      p2.validate();

      pack();
      setSize(800, 400);
      setVisible(true);
      addWindowListener(new WindowAdapter() {
                  public void windowClosing(WindowEvent we) {
                      System.exit(0);
                  }
              });
          }

         public static void main(String argv[]) {
      new rButton();
          }
      }

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                apikalev Andrey Pikalev
                Reporter:
                rphamsunw Roger Pham (Inactive)
              • Votes:
                0 Vote for this issue
                Watchers:
                0 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Imported:
                  Indexed: