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

BoxLayout lays out JComponents differently/wrong.

XMLWordPrintable

    • generic, x86
    • generic, windows_2000



      Name: gm110360 Date: 04/23/2004


      FULL PRODUCT VERSION :
      1.4.2-b28


      ADDITIONAL OS VERSION INFORMATION :
      Windows 2000

      A DESCRIPTION OF THE PROBLEM :
      When creating JButtons with setAlignmentX(LEFT_ALIGNMENT) in a JPanel with a BoxLayout, the JButtons are layed out properly (vertical). As soon as another Component (I tried it with a JList) the JButtons aren't aligned left anymore. There is a little gap between the left edge of the JPanel/container and the JButton but there is NO space between the JList and the container.


      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Just compile and run the code.


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Components should be aligned equally on the left edge of the container without any space between.


      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import javax.swing.JFrame;
      import java.awt.HeadlessException;

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

      public class Test extends JFrame
      {
        JPanel leftNavPane = new JPanel();
        JPanel mainPane = new JPanel();

        public Test()
        {
          initGuiComponents();
          setSize(800,600);
          setVisible(true);
        }

        private void initGuiComponents()
        {
          //The layout of the application itself.
          this.getContentPane().setLayout(new BorderLayout());

          mainPane.add(new JButton("Hello"));

          leftNavPane.setLayout(new BoxLayout(leftNavPane, BoxLayout.PAGE_AXIS));
          JButton b1 = new JButton("Yes");
          b1.setAlignmentX(LEFT_ALIGNMENT);
          leftNavPane.add(b1);
          leftNavPane.add(Box.createRigidArea(new Dimension(0,5)));
          JButton b2 = new JButton("No");
          b2.setAlignmentX(LEFT_ALIGNMENT);
          leftNavPane.add(b2);
          leftNavPane.add(Box.createRigidArea(new Dimension(0,5)));
          java.util.Vector v = new java.util.Vector();
          v.add(new String("1"));
          v.add(new String("2"));
          v.add(new String("3"));
          v.add(new String("4"));
          v.add(new String("5"));
          JList list = new JList(v);
          list.setVisibleRowCount(3);
          leftNavPane.add(list);

          JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,
                                     leftNavPane, mainPane);

          //this.getContentPane().add(splitPane);
          this.getContentPane().add(leftNavPane);
        }//end initGuiComponents
        //----------------------------------------------------------------------------

      public static void main(String[] args){
        new Test();
        }
      }
      ---------- END SOURCE ----------
      (Incident Review ID: 250600)
      ======================================================================

            Unassigned Unassigned
            gmanwanisunw Girish Manwani (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: