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

Box with glue has alignment, repaint problems

XMLWordPrintable

      Name: ddT132432 Date: 08/07/2001


      java version "1.3.0rc1"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0rc1-T)
      Java HotSpot(TM) Client VM (build 1.3.0rc1-S, mixed mode)


      Here's my test case:

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

      public class Test2
      {
        public static void main (String[] args)
        {
          Test2 t = new Test2();
        }

        public Test2()
        {
          JButton button = new JButton("button nottub");

          Box vBox = Box.createVerticalBox();
          vBox.add (Box.createGlue());
          vBox.add (button);
          vBox.add (Box.createGlue());

          Box hBox = Box.createHorizontalBox();
          hBox.add (Box.createGlue());
          hBox.add (vBox);
          hBox.add (Box.createGlue());

          JFrame frame = new JFrame ();
          frame.setContentPane(hBox);
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          frame.pack();
          frame.show();
        }

      }


      The code should create a button, "packed" and centered in the middle
      of the frame, which remains centered when the frame is resized.

      There are at least a couple of things wrong. First, if I resize the
      frame to be wide, the button is clearly not centered. It's
      somewhat to the left, as if hBox's right-hand glue took up too much
      of the extra space.

      Secondly, if I resize the frame to be smaller vertically or
      horizontally, the button would redraw itself, and the previous button
      would remain. This won't happen if I resize the frame smaller in
      both dimensions at once. Moreover, if I hide and re-expose part of
      the frame, it looks even worse. (This might arguably not be a bug;
      glue components are specified as non-opaque.)

      This problem might be related to 4352274 and 4140481. I did not see
      the glue-related problem mentioned anywhere in Bug Parade (though
      again, it might be arguably correct behavior).
      (Review ID: 129395)
      ======================================================================

            Unassigned Unassigned
            ddressersunw Daniel Dresser (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Imported:
              Indexed: