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

Initially empty JLabel does not show in JPanel with BorderLayout

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not an Issue
    • Icon: P4 P4
    • None
    • 1.2.0
    • client-libs

      Hi, let me first thank you for a great product. I've been playing with this stuff since 0.5 and I'm in love, especially with the JTable, JTree and Text/RTF/HTML components...

      Anyhow, I have a bug I thought I ought to report...I'm using swing-1.0.1 (I'm downloading 1.0.2 right now but anyhow...) and JDK1.1.5, and I'm creating a little inspector panel, initially just with two JLabels which I am dynamically setting the text on. I am using a BorderLayout with one added north and one center. When I first create a JFrame and set the text, only the center one appears; the north one seems lost.
      Once I resize the window the north one appears and they both re-adjust but not
      until I do so...I've tried adding the JLabels in either order, neither works.

      ------------------------------------------------------------
      This test can be used to reproduce this bug. Press the button.
      Two labels should appear: "north" on top of the frame and
      "center" below.

      ###@###.### 2000-06-23


      /** Works with 1.2 and above, fails with 1.1.x & Swing 1.0.x
       * Press the button -- two labels titled "north" and "center"
       * should appear
       */
      import java.awt.*;
      import java.awt.event.*;
      import com.sun.java.swing.*;
      // import javax.swing.*;

      public class bug4139756
      {
          public static void main(String[] argv) {
              JFrame f = new JFrame("4139756");
      // JLabel north = new JLabel("North");
      // JLabel center = new JLabel("Cebter");
              final JLabel north = new JLabel();
              final JLabel center = new JLabel();
              final JButton b = new JButton("set-text");

              b.addActionListener(new ActionListener() {
                      public void actionPerformed(ActionEvent ev) {
                          north.setText("north");
                          center.setText("center");
                      }
                  });

              Container p = f.getContentPane();
              p.add(north, BorderLayout.NORTH);
              p.add(center, BorderLayout.CENTER);
              p.add(b, BorderLayout.SOUTH);

              f.setSize(100,100);
              f.setVisible(true);
          }
      }
      ------------------------------------------------------------

            sswingtrsunw Swingtraq Swingtraq (Inactive)
            rkarsunw Ralph Kar (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: