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

TitledBorder setenabled(false) changes do not appear until repaint() is called

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Won't Fix
    • Icon: P4 P4
    • None
    • 1.3.1, 1.4.1, 1.4.2
    • client-libs



      Name: jk109818 Date: 08/13/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 OS VERSION :
      Microsoft Windows 2000 [Version 5.00.2195]


      A DESCRIPTION OF THE PROBLEM :
      Changing the text color or even the text of a TitledBorder fails to display until a repaint is forced. While changing only the color might not be expected to cause a repaint automatically, changing the text causes a change to the "size" characteristics of the border and hence, it would seem, should automatically cause the layout to be recalculated and a subsequent repaint.

      What I really want is for a TitledBorder to dim around a "disabled" control using Windows Look and Feel. This behavior did not occur when JPanels with TitledBorders were setEnabled(false). In my case, I have a control with three JPanels with TitledBorders. One JPanel is really a class that extends JPanel, the other two are built from JPanels in the class that builds the three part control. Checkboxes then enable and disable each of the three sub-controls. Changing the TitledBorder characteristics on the extension of JPanel works fine, but the other two JPanels require repaints. The test case below demonstrates the failure.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Compile and run the code below. Checking the checkbox should cause the TitledBorder text to change and be dimmed.

      Remove the call to repaint(). Now the checkbox has no effect. However, resizing the JFrame will cause the dimmed and changed text to appear.


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      I expected the changed, dimmed text to appear without requiring a repaint(). It is possible that I just have misunderstood the way swing repaints. However, since I don't have to force repaints to make changed button or label text appear, I wouldn't expect to with a title. If the exhibited behavior is correct, then I would ask for a documentation change to make this clear.

      In fact, using Windows LAF, I expected the title text to dim automatically when I did a setEnabled(false) on the JPanel without my having to do a setTitleColor.

      (Other things I tried: 1) validate() did nothing to help. 2) Actually doing a setBorder on the Jpanel did force the changes to appear. 3) I was unable to replicate my extended JPanel behavior (which worked) in a simple test case. I am assuming the more complicated code that I have is somehow forcing a repaint to occur.)
      The dimmed or changed text only appears after a repaint or size change.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.awt.Color;
      import java.awt.BorderLayout;
      import java.awt.event.WindowAdapter;
      import java.awt.event.ItemEvent;
      import java.awt.event.WindowEvent;
      import java.awt.event.ItemListener;
      import javax.swing.border.TitledBorder;
      import javax.swing.JPanel;
      import javax.swing.JFrame;
      import javax.swing.JButton;
      import javax.swing.JCheckBox;
      public class BorderTest extends JFrame {
          private JPanel jp;
          public BorderTest() {
              jp = new JPanel();
              JButton jb = new JButton();
              JCheckBox jc = new JCheckBox();
              addWindowListener(new WindowAdapter() {
                  public void windowClosing(WindowEvent evt) {
                      System.exit(0);
                  }
              });
              jp.setBorder(new TitledBorder("Title should dim"));
              jb.setText("Button");
              jp.add(jb);
              getContentPane().add(jp, BorderLayout.CENTER);
              jc.setText("CheckBox");
              jc.addItemListener(new ItemListener() {
                  public void itemStateChanged(ItemEvent evt) {
                      ((TitledBorder) jp.getBorder()).setTitleColor(new Color(128,128,128));
                      ((TitledBorder) jp.getBorder()).setTitle("Title change");
                      jp.repaint();
                  }
              });
              getContentPane().add(jc, BorderLayout.SOUTH);
              pack();
          }
          public static void main(String args[]) {
              new BorderTest().show();
          }
      }

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

      CUSTOMER SUBMITTED WORKAROUND :
      A call to repaint() after changing the color or text of the TitledBorder causes the changes to be displayed.
      (Incident Review ID: 184518)
      ======================================================================

            leifs Leif Samuelsson (Inactive)
            jkimsunw Jeffrey Kim (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: