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

1.3RC1 Regression: JMenu popup width wrong after removeAll()

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 1.4.0
    • 1.3.0
    • client-libs
    • beta2
    • generic, x86
    • generic, windows_nt



      Name: krT82822 Date: 04/02/2000


      4/2/2000 eval1127@eng -- filing a bug only because this represents a regression vs. 1.2.2. A workaround exists.

      java version "1.3.0rc1"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0rc1-T)
      Java HotSpot(TM) Client VM (build 1.3.0rc1-S, mixed mode)

      There has been a change in 1.3RC1 which results in the popup of a JMenu not
      being sized correctly after a removeAll() is done on the menu. This worked
      correctly in 1.2.2, 1.3beta and 1.3RA.

      This also may be platform independent, but I only have 1.3RC1 available on the
      NT systems I use.

      The problem involves using removeAll() to clear a menu then filling it with
      calls to add(). When doing this, the width of the menu doesn't change to reflect
      the size of the new items. Here's the problem graphically:

      ### Before changning menu content menu looks like this
            ________________________
            | A long piece of text |
             -----------------------

      ### After calling removeAll() on the menu then calling add()
            ________________________
            | Hi |
             -----------------------


      I think you can see that the width after the removeAll() should be MUCH
      smaller. I'm at a loss how to correct this eye-sore and was hoping
      someone could take the simple test program below and make it do what I
      want. After invoking the test app click the "Test" menu button _FIRST_ to see
      the size the menu item has initially. Then click the "Click to do the test"
      button and look at the menu again ... :-(


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

      public class MenuResize extends JFrame {
         public static void main(String[] args) {
            new MenuResize();
         }
         private JMenu m;

         public MenuResize() {
            addWindowListener(new WindowAdapter() {
               public void windowClosing(WindowEvent e) {
                  System.exit(0);
               }}
            );
            JMenuBar mbar = new JMenuBar();
            setJMenuBar(mbar);

            m = new JMenu("Test");
            JMenuItem mi = new JMenuItem("This is a long piece of text");
            m.add(mi);
            JButton b = new JButton("Click to do the test");
            b.addActionListener(new ActionListener() {
               public void actionPerformed(ActionEvent e) {
                  m.removeAll();
                  m.add(new JMenuItem("Hi"));
               }}
            );
            mbar.add(m);
            mbar.add(b);
            pack();
            setBounds(300,300,300,300);
            setVisible(true);
         }
      }
      (Review ID: 102986)
      ======================================================================

            peterz Peter Zhelezniakov
            kryansunw Kevin Ryan (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: