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

JTabbedPane.setTitleAt() doesn't refresh when using HTML text

XMLWordPrintable

    • beta
    • generic
    • generic



      Name: krT82822 Date: 09/19/99


      9/19/99 eval1127@eng -- reproducible with kestrel-beta. Can't figure out how to work around the apparent problem. Filing new bug (can't find dupe).

      Swing 1.1.1 FCS introduced the option to include HTML formatted labels
      in many components, e.g. the titles of a JTabbedPane.

      However, when one has defined a tab using such HTML label, and one
      tries to change its contents using setTitleAt(), nothing gets
      redisplayed.

      When using standard labels (non HTML), the app works find, and the
      tab labels get updated as expected.

      The following test program shows the behavior. Clicking on the button in
      first tab changes its label, while clicking the button in the second tab
      doesn't have any effect.


      --------------- revised test case, including extraneous calls which attempt (unsuccessfully) to force repaint/update: ------------

      import javax.swing.*;
      import java.awt.event.*;

      public class test95435 {

              static JTabbedPane tabs;
              static JFrame f;

              public static void main(String args[]) {
                      f = new JFrame();
                      tabs = new JTabbedPane();
                      f.getContentPane().add(tabs);
                      JButton t1 = new JButton("test95435_t1");
                      tabs.addTab("Label1",t1);
                      JButton t2 = new JButton("test95435_t2");
                      tabs.addTab("<html>Label2</html>",t2);
                      t1.addActionListener(new ActionListener() {
              
                              public void actionPerformed(ActionEvent e) {
                                              SwingUtilities.invokeLater(
                                                      new Runnable() {
                                              public void run() {
                                                      tabs.setTitleAt(0,"new label");
                                              }
                                                      } );
                              }
                      });
                      t2.addActionListener(new ActionListener() {
              
                              public void actionPerformed(ActionEvent e) {
                                              SwingUtilities.invokeLater(
                                                      new Runnable() {
                                              public void run() {
                                                      tabs.setTitleAt(
                                                              1,"<html>new label</html>");
                                                      tabs.revalidate(); // added
                                                      tabs.repaint(); // added (trying to force repaint)
                                                      f.repaint(); // still trying...
                                              }
                                                      } );
                              }
                      });

                      f.pack();
                      f.show();
              }
      }
      ------------------






      --------- orig test case --------------------------------

      import javax.swing.*;
      import java.awt.event.*;
      public class test {

              static JTabbedPane tabs;

              public static void main(String args[]) {
                      JFrame f = new JFrame();
                      tabs = new JTabbedPane();
                      f.getContentPane().add(tabs);
                      JButton t1 = new JButton("test");
                      tabs.addTab("Label1",t1);
                      JButton t2 = new JButton("test");
                      tabs.addTab("<html>Label2</html>",t2);
                      t1.addActionListener(new ActionListener() {
                              public void actionPerformed(ActionEvent e) {
                                      tabs.setTitleAt(0,"new label");
                              }
                      });
                      t2.addActionListener(new ActionListener() {
                              public void actionPerformed(ActionEvent e) {
                                      tabs.setTitleAt(1,"<html>new label</html>");
                              }
                      });
                      f.pack();
                      f.show();
              }
      }
      (Review ID: 95435)
      ======================================================================

            apikalev Andrey Pikalev
            kryansunw Kevin Ryan (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: