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

TitledBorder inside EmptyBorder Bug reappears in Swing 1.1.1

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 1.4.0
    • 1.2.0, 1.2.2, 1.3.0
    • client-libs
    • beta
    • generic, x86, sparc
    • generic, solaris_2.6, windows_nt



      Name: skT88420 Date: 08/27/99


      When a TitledBorder is inside an EmptyBorder, it does not paint
      completely. The title is at the top. The lower line only goes
      from the lower left corner to where the string would start if
      it were at the bottom. The lower right corner is not painted.

      I realize this was qualified as a duplicate of bugs no. 4154904
      and 4128981. It was fixed in swing 1.1. But it reappears in
      swing 1.1.1! (size of swingall.jar I used: 2.420.388)

      The solution given in 4128981 (grooveRect variable, in
      TitledBorder.java) is implemented in the swingall.jar I use,
      according to the src.zip that comes with swing 1.1.1,
      but apparently it does not solve the problem. I retested the
      code examples for the above mentioned bugs, too, and all
      (including my own) work fine with swing 1.1 but are broken
      again in 1.1.1 .


      Example source code:
      -------------------------------------------------------------

      import java.awt.event.WindowAdapter;
      import java.awt.event.WindowEvent;
      import javax.swing.*;
      import javax.swing.border.*;

      public class TitledBorderExample extends JFrame
      {
          public TitledBorderExample()
          {
              JPanel panel = new JPanel();
              JLabel label = new JLabel("Sample Text");

              getContentPane().add(panel);

              Border b = getBox(new String("Title"));
              panel.setBorder(b);
              panel.add(label);
              pack();
          }

          private Border getBox(String text)
          {
              Border out_pad, etched, title;

              etched = BorderFactory.createEtchedBorder();
              out_pad= BorderFactory.createEmptyBorder(4,0,0,0);
              title = BorderFactory.createTitledBorder(etched, text,
                                                TitledBorder.TOP, TitledBorder.CENTER);
              //1. parameter = outer border
              //2. parameter = inner border
              return BorderFactory.createCompoundBorder(out_pad, title);
          }

          public static void main(String[] args)
          {
              TitledBorderExample ex = new TitledBorderExample();
              ex.addWindowListener(new WindowAdapter()
              {
                  public void windowClosing(WindowEvent e){System.exit(0);}
              });
              ex.setVisible(true);
          }
      }
      -----------------------------------------------------
      (Review ID: 94512)
      ======================================================================

      Name: rlT66838 Date: 11/05/99


      java version "1.2.2"
      Classic VM (build JDK-1.2.2-W, native threads, symcjit)

      and also

      java version "1.2.2"
      Java HotSpot(TM) Server VM (2.0beta, mixed mode, build G)
      Switching from JDK 1.2.1 to 1.2.2 I noticed that nested borders are not painted
      correct any more. This is also true to the JDK 1.3beta.

      I added an example to show up the problem. Usage: java Borders <i>
      where <i> stands for a number to be entered. For <i> > 3 the problem can be
      seen.

      I also searched the bug parade regarding this problem and found the bugs
      4154904 and 4154904. Both were closed in Swing 1.1. But it seems that by chance
      the error slipped into JDK 1.2.2

      // --- Example code ---

      import javax.swing.*;
      import javax.swing.border.*;

      import java.awt.*;
      import java.awt.event.*;

      public class Borders
      {
         JFrame frame;
         
         public Borders(String args[])
         {
         // different panels
         
            JPanel northPanel = new JPanel();
            JPanel westPanel = new JPanel();
            JPanel southPanel = new JPanel();
            JPanel eastPanel = new JPanel();
            JPanel centerPanel = new JPanel();

            String text = "This is a panel in the ";
         
            northPanel .add(new JLabel(text + "north"));
            westPanel .add(new JLabel(text + "west"));
            southPanel .add(new JLabel(text + "south"));
            eastPanel .add(new JLabel(text + "east"));
            centerPanel.add(new JLabel(text + "center"));
            
            northPanel .setBorder(getBorder(args));
            westPanel .setBorder(getBorder(args));
            southPanel .setBorder(getBorder(args));
            eastPanel .setBorder(getBorder(args));
            centerPanel.setBorder(getBorder(args));

         // main panel
         
            JPanel mainPanel = new JPanel(new BorderLayout());
            
            mainPanel.add("North", northPanel);
            mainPanel.add("West", westPanel);
            mainPanel.add("South", southPanel);
            mainPanel.add("East", eastPanel);
            mainPanel.add(centerPanel);
            
         // frame
               
            frame = new JFrame();
            frame.getContentPane().add(mainPanel);
            frame.pack();
            frame.addWindowListener(new WindowAdapter()
            {
               public void windowClosing(WindowEvent e)
               {
                  System.exit(0);
               }
            });
            frame.setVisible(true);
         }
         
         public AbstractBorder getBorder(String args[])
         {
            if (args == null || args.length == 0)
            {
               return null;
            }
            else if ("1".equals(args[0]))
            {
               return new EmptyBorder(10, 10, 5, 5);
            }
            else if ("2".equals(args[0]))
            {
               return new TitledBorder("Title 2");
            }
            else if ("3".equals(args[0]))
            {
               return new TitledBorder(new EtchedBorder(), "Title 3");
            }
            else if ("4".equals(args[0]))
            {
                new CompoundBorder(new EmptyBorder(10,5,10,5),
                                   new TitledBorder(new EtchedBorder(), "Title 4"));
            }
            else if ("5".equals(args[0]))
            {
                new CompoundBorder(new TitledBorder(new EtchedBorder(), "Title 5"),
                                   new EmptyBorder(10,5,10,5));
            }
            else if ("6".equals(args[0]))
            {
               return new CompoundBorder(
                   new CompoundBorder(
                         new EmptyBorder(10,5,10,5),
                         new TitledBorder(new EtchedBorder(), "Title 6")),
                   new EmptyBorder(10, 10, 5, 5));
            }
            else if ("7".equals(args[0]))
            {
               return BorderFactory.createCompoundBorder(
                   BorderFactory.createCompoundBorder(
                         BorderFactory.createEmptyBorder(10,5,10,5),
                         
      BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), "Title
      7")),
                   BorderFactory.createEmptyBorder(10, 10, 5, 5));
            }
            
            return null;
         }

         public static void main(String args[])
         {
            Borders b = new Borders(args);
         }
      }
      (Review ID: 97518)
      ======================================================================

            amfowler Anne Fowler (Inactive)
            skonchad Sandeep Konchady
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: