JDK-4146342 : Menu mouse events also get delivered to components under the menu
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 1.1.6
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_nt
  • CPU: x86
  • Submitted: 1998-06-05
  • Updated: 1998-06-10
  • Resolved: 1998-06-10
Related Reports
Duplicate :  
Description

Name: el35337			Date: 06/05/98


Using swing 1.0.2 and jdk1.1.6.
The program below prints "menu action" when the menu item "Item"
is selected from the menu. When a table header is mouse clicked
it prints the name of the column.
To see the problem, click on menu (release the mouse button, the menu
stays down) then move the mouse button over the word "Item" in the menu
and see it highlighted. Then click on the word item, this causes
"menu action" to be printed, but "Click on Name" is also printed. Its
a bug that the menu mouse event also gets delivered to the table header
component.

========CUT HERE============================

package bug06;

import java.awt.*;
import java.beans.*;
import com.sun.java.swing.*;
import com.sun.java.swing.event.*;
import com.sun.java.swing.table.*;
import java.awt.event.*;
import java.io.*;

public class xx extends JFrame {
  JPanel southPanel = new JPanel();
  JScrollPane jScrollPane1 = new JScrollPane();
  JTable whoTable = new JTable();
  JMenuBar menuBar = new JMenuBar();
  JMenu help = new JMenu();
  JMenuItem aboutWindowM = new JMenuItem();
  BorderLayout borderLayout = new BorderLayout();

  public xx() {
    this.getContentPane().setLayout(borderLayout);
    new BoxLayout(southPanel, BoxLayout.Y_AXIS);

    help.setText("Menu");
    aboutWindowM.setText("Item");

    this.getContentPane().add(southPanel, BorderLayout.SOUTH);
    this.getContentPane().add(jScrollPane1, BorderLayout.CENTER);
    jScrollPane1.getViewport().add(whoTable, null);
    menuBar.add(help);
    help.add(aboutWindowM);

    this.setJMenuBar(menuBar);

    whoTable.setModel(new WhoTableModel());
    aboutWindowM.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        System.out.println("menu action");
      }
    });
    whoTable.getTableHeader().addMouseListener(new MouseAdapter() {
      public void mouseClicked(MouseEvent e) {
        int col = whoTable.getColumnModel().getColumnIndexAtX(e.getX());
        if(col != -1 && e.getClickCount() == 1) {
          System.out.println("Click on \""+columnNames[col]+"\"");
        }
      }
    });
  }

  final String columnNames[] = { "Name", "Rank", "Idle", "Obs", "Pla", "Inf" };

  class WhoTableModel extends AbstractTableModel {
    public int getRowCount() { return 3; }
    public int getColumnCount() { return columnNames.length; }
    public String getColumnName(int column) { return columnNames[column]; }
    public Object getValueAt(int row, int column) {
      return new Integer(row+column);
    }
  }

  public static void main(String[] args) {
    xx wf = new xx();
    wf.pack();
    wf.setVisible(true);
  }
}
(Review ID: 33182)
======================================================================

Comments
EVALUATION This is a duplicate
11-06-2004