JDK-4137555 : If JFrame is resized then JMenu's dropdown changes its position
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 1.1.5
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • OS: solaris_2.6
  • CPU: sparc
  • Submitted: 1998-05-12
  • Updated: 1998-06-01
  • Resolved: 1998-06-01
Related Reports
Duplicate :  
Description
Using swing-1.0.1 with /set/java/jdk/JavaSoft/sparc-S2/jdk1.1.5.
Solaris 5.6.

To reproduce:

1) Shrink a JFrame so it's very narrow.
2) Drop down some of the menus. 
- There's a gap between the dropdown and the menubar
3) Restore the JFrame back to its original size.
4) Drop down the menus again.  
- dropdown still in the wrong position.

Another symptom is the Dropdown may partially cover the menubar.

Here's a sample program:

/**
 * JComps demonstrates the use of menus in Swing and adding and removing
 * Swing components to a JPanel.  
 *
 */

import java.awt.*;
import java.awt.event.*;
import com.sun.java.swing.*;

/**
 * JComps
 * 
 */
public class JComps extends JFrame implements ActionListener, ContainerListener 
{
  JLabel lOutput = new JLabel("Action goes here");
  Container contentPane;
  JPanel compsPanel;
  int i = 0;

/**
 * JComps constructor
 * 
 */
  public JComps() {
    super("JComps");  
    setSize(500,500);
    contentPane = getContentPane();
    contentPane.setLayout(new BorderLayout());
    JMenuBar jmb = new JMenuBar();
    JMenu jCompMenu = new JMenu("Component");
    JMenuItem textAreaItem = new JMenuItem("Add JTextArea");
    textAreaItem.addActionListener(this);
    JMenuItem listItem = new JMenuItem("Add JList");
    listItem.addActionListener(this);
    JMenuItem labelItem = new JMenuItem("Add JLabel");
    labelItem.addActionListener(this);
    JMenu jRemoveMenu = new JMenu("Remove");
    JMenuItem rItem = new JMenuItem("Remove Component");
    rItem.addActionListener(this);
    JMenuItem exitItem = new JMenuItem("Exit");
    exitItem.addActionListener(this);
    jCompMenu.add(textAreaItem);
    jCompMenu.add(listItem);
    jCompMenu.add(labelItem);
    jCompMenu.add(exitItem);
    jRemoveMenu.add(rItem);
    jmb.add(jCompMenu);
    jmb.add(jRemoveMenu);
    setJMenuBar(jmb);  
    compsPanel = new JPanel();
    compsPanel.addContainerListener(this);
    compsPanel.setLayout(new BorderLayout());
    compsPanel.setBackground(Color.white);
    Label lbl = new Label("Component chosen from menu");
    compsPanel.add(lbl, "South");
    contentPane.add(lOutput, "South");
    contentPane.add(compsPanel, "Center");
    addMouseListener(new MyMouseAdapter());
  }

    /** All menu item commands are handled by this method
    */
    public void actionPerformed(ActionEvent e) {
        String cmd = e.getActionCommand();

        if (cmd.equals("Add JTextArea")) {
            lOutput.setText("JTextArea menuitem chosen");
            JTextArea jta;
            jta = new JTextArea("This is text inside a JTextArea");
            jta.setMinimumSize(new Dimension(1, 1));
            compsPanel.add(jta, "Center");
	    compsPanel.validate();         
        } else if (cmd.equals("Add JList")) {
            lOutput.setText("JList menuitem chosen");  

            // instantiate new list
            String[] items = {"one", "two", "free", "four"};
            JList list = new JList(items);
            compsPanel.add(list, "Center");
	    compsPanel.validate();
        } else if (cmd.equals("Add JLabel")) {
            lOutput.setText("JLabel menuitem chosen");  
       
            // instantiate new label
            JLabel lb = new JLabel("this is a JLabel");
            // lb.addActionListener(this);  ** won't compile **

            compsPanel.add(lb, "Center");
	    compsPanel.validate();
        } else if (cmd.equals("Remove Component")) {
            lOutput.setText("Remove component menuitem chosen");
            
            // remove previous component from container
            Component cmp = compsPanel.getComponent(1);          

            if (cmp != null) {
                compsPanel.remove(cmp);
                compsPanel.validate();
            }
        } else if (cmd.equals("Exit")) {
          System.out.println("Exit menuitem was chosen");
          dispose();

        }
    } // end of  actionPerformed(ActionEvent e) 

   // Container event handler methods
   public void componentAdded(ContainerEvent e) {
       System.out.println("COMPONENT_ADDED:  " + e.getChild());
   }
   public void componentRemoved(ContainerEvent e) {
       System.out.println("COMPONENT_REMOVED:  " + e.getChild());
   }

/**
 * not implemented
 */
    class MyMouseAdapter extends MouseAdapter {}
/**
 * not implemented
 */
    class MyMouseMotionAdapter extends MouseMotionAdapter {}
/**
 * not implemented
 */
    class MyKeyAdapter extends KeyAdapter {}

  public static void main(String args[]) { 
      JComps jc = new JComps();
      jc.setVisible(true);
  }

}






Comments
EVALUATION This is a known AWT bug. I don't have the number handy, but it is a duplicate. georges.saab@Eng 1998-05-18 Found it -- 4103095. That bug is fixed in 1.1.6, and I've verified the fix against the sample code. The reported behavior does not happen (not reproducible).
18-05-1998