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

Box disregards setBackground() even when set Opaque(true)

    Details

    • Subcomponent:
    • Resolved In Build:
      b53
    • CPU:
      x86
    • OS:
      windows_xp

      Description

      Name: jk109818 Date: 08/15/2003


      FULL PRODUCT VERSION :
      java version "1.4.0"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-b92)
      Java HotSpot(TM) Client VM (build 1.4.0-b92, mixed mode)


      FULL OS VERSION :
      Microsoft Windows XP [Version 5.1.2600]

      A DESCRIPTION OF THE PROBLEM :
      Box disregards the background property even when set to opaque, which is
      inconstent with the documented behaviour of Swing (in containers such as
      JPanel).

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Create a Box, set its background and place a glue in it. Set it to be opaque.
      Yet when shown the background will not match the one set.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The background should appear correctly (see sample code and workaround)
      ACTUAL -
      The color is the default OS background color

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.awt.Color;
      import javax.swing.*;

      public class BoxTest extends JFrame {
          /**
           * Constructor for the BoxTest object
           */
          public BoxTest() {
              Box b = new Box(BoxLayout.X_AXIS);
              // Uncomment these lines for a workaround
              //JPanel b = new JPanel();
              //b.setLayout(new BoxLayout(b, BoxLayout.X_AXIS));
              b.setBackground(Color.PINK);
              b.setOpaque(true);
              b.add(Box.createGlue());
              getContentPane().add("Center", b);
              pack();
          }


          /**
           * The main program for the BoxTest class
           *
           *@param argv The command line arguments
           */
          public static void main(String[] argv) {
              new BoxTest().show();
          }
      }

      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Replace:
         Box b = new Box(BoxLayout.X_AXIS);

      with:
         JPanel b = new JPanel();
         b.setLayout(new BoxLayout(b, BoxLayout.X_AXIS));
      (Incident Review ID: 188567)
      ======================================================================

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                svioletsunw Scott Violet (Inactive)
                Reporter:
                jkimsunw Jeffrey Kim (Inactive)
              • Votes:
                0 Vote for this issue
                Watchers:
                0 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Imported:
                  Indexed: