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

setLabel() method for MenuItems adds space in front of label

XMLWordPrintable

    • x86
    • windows_95



      Name: rm29839 Date: 03/12/98


      After creating a MenuItem, then later changing its label in the actionPerformed() method using the setLabel() method, the label
       shown in the GUI has an extra space mysteriously added to the front of it. Here's the source:

      This is seen ONLY on win95 (not NT or Solaris)

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

      class Test extends Frame implements ActionListener
      {
      Menu menuTest;
      MenuItem menuTestToggle;

      Test(String title)
      {
      setTitle(title);

      addWindowListener(new WindowAdapter()
      {
               public void windowClosing(WindowEvent event)
      {
      System.exit(0);
      }
      });

      // Create menu bar
            MenuBar menuBar = new MenuBar();
      setMenuBar(menuBar);

      // Create "Test" menu
      menuTest = new Menu("Test");
      menuTest.addActionListener(this);
      menuBar.add(menuTest);
      menuTestToggle = new MenuItem("Start");
      menuTest.add(menuTestToggle);
      menuTestToggle.addActionListener(this);
      }

         public void actionPerformed(ActionEvent event)
      {
      String menuItem = event.getActionCommand();

      if (menuItem == "Start")
      {
      ((MenuItem)event.getSource()).setLabel("Stop");
      }
      else if (menuItem == "Stop")
      {
      ((MenuItem)event.getSource()).setLabel("Start");
      }
      }

      public static void main(String args[])
      {
      Test wdw = new Test("Test");
      wdw.pack();
      wdw.show();
      }
      }
      (Review ID: 26111)
      ======================================================================

            feckssunw Fred Ecks (Inactive)
            rmandelsunw Ronan Mandel (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: