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

TitledBorder Bug of API Documentation or Bug of Specification

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P4
    • None
    • 1.4.1
    • client-libs
    • Fix Understood
    • x86
    • linux

    Description



      Name: jk109818 Date: 03/31/2003


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


      FULL OPERATING SYSTEM VERSION : Vine linux 2.5


      A DESCRIPTION OF THE PROBLEM :
      I think there's at least one problem with TitledBorder when
      creating it without specifying its border, font and color.

       1. TitledBorder's document is ambiguous OR
       2. TitledBorder has a bug.

       API Doc says

      >If the border, font, or color property values are not
      >specified in the constuctor or by invoking the appropriate
      >set methods, the property values will be defined by the current
      >look and feel, using the following property names in the
      >Defaults Table:
      > TitledBorder.border
      > TitledBorder.font
      > TitledBorder.titleColor

       It lacks an explanation of what happend if default LAF is
      changed without updateUI(). Actually, TitledBorder follows
      LAF changes. IE, TitledBorder silently changes its border,
      font and color. Although I think this is not an intent of a
      developer, some explanation is necessary if it is the
      specification of TitledBorder.

       If it is a bug, how do we fix it? It is easy that we get
      its border, font, color from the "current" LAF at
      TitledBorder's creation time. It is a satisfying solution if
      we never change current LAF or never update component-UI.

       But, what should we do if we want to change current LAF AND
      update component-UI?
       Besides, TitledBorder can be shared with multiple
      components with different LAF.
       And we want TitledBorder's rendering to be changed along
      with LAF change. If we use a LAF with large font, the TITLE
      should be large.

       I think the only solution is something like the following.

       1. Create TitledBorder2 class.
       2. Never define public
      getBorder(),getTitleColor(),getTitleFont() methods with no
      arguments. These are indeterminate unless we specify the
      component that TitledBorder2 target at. Again, Borders can
      be shared with multiple components.
       3. At the point of getBorderInsets() or paintBorder()
      methods are called, we must get border, font and color from
      the LAF of the component that specified as argument.
      (Although it seems that there's no way of finding LAF from a
      component).


      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.awt.*;
      import java.awt.event.*;

      import javax.swing.*;
      import javax.swing.border.*;
      import javax.swing.plaf.*;
      import javax.swing.plaf.metal.*;

      import com.sun.java.swing.plaf.motif.*;

      public class Test extends JFrame {
        public static void main(String[] args) {
          try {
            UIManager.setLookAndFeel(new MotifLookAndFeel());
          } catch (Exception ex) {
          }
          Test f = new Test();
          f.validate();
          f.show();
        }
        Test() {
          JPanel contentPane = (JPanel) this.getContentPane();
          contentPane.setLayout(new BorderLayout());
          this.setSize(new Dimension(400, 300));
          JPanel panel = new JPanel();
          panel.setBorder(new TitledBorder("title"));
          JButton button = new JButton();
          button.setText("AFTER CLICKING THIS, REPAINT THE FRAME");
          button.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(ActionEvent e) {
              changeLAF();
            }
          });
          contentPane.add(panel, BorderLayout.CENTER);
          panel.add(button, null);
        }

        void changeLAF() {
            MetalLookAndFeel.setCurrentTheme(new DefaultMetalTheme() {
              private FontUIResource font = new FontUIResource("Dialog", Font.BOLD, 40);
              private ColorUIResource color = new ColorUIResource(Color.red);
              public FontUIResource getControlTextFont() { return font; }
              public ColorUIResource getSystemTextColor() { return color; }
            });
          try {
            UIManager.setLookAndFeel(new MetalLookAndFeel());
          } catch (Exception ex) {
          }
        }
      }
      ^E
      ---------- END SOURCE ----------
      (Review ID: 180149)
      ======================================================================

      Attachments

        Activity

          People

            tr Tejesh R
            jkimsunw Jeffrey Kim (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Imported:
              Indexed: