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

calling JButton.setAction clears button text

    XMLWordPrintable

    Details

      Description

      FULL PRODUCT VERSION :
      java version "1.6.0"
      Java(TM) SE Runtime Environment (build 1.6.0-b105)
      Java HotSpot(TM) Client VM (build 1.6.0-b105, mixed mode, sharing)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows XP [Version 5.1.2600]

      A DESCRIPTION OF THE PROBLEM :
      If an action is set on a JButton, the button's text is cleared. Same as 4266524, except for 1.6.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Instantiate a button, set text with setText(), set action with setAction(). Button's text is cleared.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The button's text should be displayed even though an action is set on the button.
      ACTUAL -
      The button's text is cleared if setAction() is called after setText().

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import javax.swing.*;
      import java.awt.*;
      import java.awt.event.ActionEvent;

      public class TestSetAction extends JPanel {

          public TestSetAction() throws HeadlessException {
              JButton button = new JButton();
              button.setText("setText first");
              button.setAction(new TestAction());
              add(button);
              JButton button2 = new JButton();
              button2.setAction(new TestAction());
              button2.setText("setAction first");
              add(button2);
          }

          private static void createAndShowGUI() {
              JFrame frame = new JFrame();
              frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              frame.add(new TestSetAction());
              frame.pack();
              frame.setVisible(true);
          }

          public static void main(String[] args) {
              javax.swing.SwingUtilities.invokeLater(new Runnable() {
                  public void run() {
                      createAndShowGUI();
                  }
              });
          }

          private class TestAction extends AbstractAction {
              public void actionPerformed(ActionEvent e) {
              }
          }
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      As long as it's possible to call setText() after setAction(), the button displays fine.

        Attachments

          Activity

            People

            Assignee:
            svioletsunw Scott Violet (Inactive)
            Reporter:
            keshah Ketan Shah (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: