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

JTable + JPopupMenu problem

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P3 P3
    • None
    • 1.2.0
    • client-libs

      When a JTable has a popup menu and the right mouse button is pressed, held, and dragged to highlight various menu items (Motif-style popup menu behavior), corresponding JTable rows also become selected/deselected.

      This problem is seen on Win NT and Solaris with JDK1.1.5 and swing-pre-1.0 release.


      Steps to reproduce the same,
      1. Run the Application.
      2. Right Click on 'Verified by 5' cell - The menu pops up.
      3. Keeping the key pressed, move the mouse over the popup menu.
      4. The menu items are selected/deselected and so also the rows of the table.
      5. The rows should not get selected/deselected when the menu is activated.


      Sample Code is given below,


      -- Sample Code --
      import java.io.*;
      import java.util.*;
      import java.awt.*;
      import java.awt.event.*;
      import com.sun.java.swing.*;
      import com.sun.java.swing.JTable.*;
      import com.sun.java.swing.JScrollPane.*;



      public class TestJTable03 extends JFrame implements MouseListener{
      /*************************************** Bug Description ***************************************/

      String[] strBugDesc = { "",
      "",
      "",
      "",
      "This TestCase tests the JTable Component",
      "Problem : When a JTable has a popup menu and the right mouse button is pressed, held,",
      "and dragged to highlight various menu items (Motif-style popup menu",
      "behavior), corresponding JTable rows also become selected/deselected.",
      "",
      "Steps to reproduce :",
      "1. Right Click on 'Verified by 5' cell - The menu pops up.",
      "2. Keeping the key pressed, move the mouse over the popup menu.",
      "3. The menu items are selected/deselected and so also the rows of the table.",
      "",
      "Pass/Fail Criteria : ",
      "Pass -- The rows of the table should not get selected/deselected when the menu items are selected/deselected.",
      "",
      "",
      "",
      ""};
        /*************************************** Bug Description ***************************************/

      Container content;
      JTable table;
      JPanel tablepanel;
      JPopupMenu popup;
      JMenuItem menuitem;
      Object[][] data = {
      {"1", "Description for 1", "Submitted by 1", "Integrated by 1", "Verified by 1" },
      {"2", "Description for 2", "Submitted by 2", "Integrated by 2", "Verified by 2" },
      {"3", "Description for 3", "Submitted by 3", "Integrated by 3", "Verified by 3" },
      {"4", "Description for 4", "Submitted by 4", "Integrated by 4", "Verified by 4" },
      {"5", "Description for 5", "Submitted by 5", "Integrated by 5", "Verified by 5" },
      {"6", "Description for 6", "Submitted by 6", "Integrated by 6", "Verified by 6" },
      };

      Object[] colHeaders = {"Bug ID", "Description", "Submitted by", "Integrated by", "Verified by"};


      TestJTable03(String[] args) {
      displayBugDesc();
      content = getContentPane();
      content.setLayout(new BorderLayout());

      tablepanel = new JPanel();
      popup = new JPopupMenu("This is the popupmenu for the table.");
      menuitem = new JMenuItem("These");
      popup.add(menuitem);

      menuitem = new JMenuItem("are");
      popup.add(menuitem);

      menuitem = new JMenuItem("the");
      popup.add(menuitem);

      menuitem = new JMenuItem("items");
      popup.add(menuitem);

      menuitem = new JMenuItem("in");
      popup.add(menuitem);

      menuitem = new JMenuItem("the");
      popup.add(menuitem);

      menuitem = new JMenuItem("menu");
      popup.add(menuitem);


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


      table = new JTable(data, colHeaders);
      table.addMouseListener(this);
      JScrollPane pane = JTable.createScrollPaneForTable(table);
      pane.setPreferredSize(new Dimension(500, 200));
      tablepanel.add(pane);

      tablepanel.setPreferredSize(new Dimension(1000, 400));

      content.add("Center", tablepanel);
      pack();
      show();
      }




      public void mouseClicked(MouseEvent e) {

      }

      public void mouseEntered(MouseEvent e) {
      }

      public void mouseExited(MouseEvent e) {
      }

      public void mousePressed(MouseEvent e) {
      if(e.getModifiers() == Event.META_MASK) {
      System.out.println("Right Button Click");
      popup.show(this, e.getX(), e.getY());
      popup.setLocation(e.getX(), e.getY());
      }

      else if(e.getModifiers() == Event.ALT_MASK) {
      System.out.println("Middle Button Click");
      }

      else {
      System.out.println("Left Button Click");
      }

      }

      public void mouseReleased(MouseEvent e) {
      }


      public void displayBugDesc() {
      int n = strBugDesc.length;
      System.out.println("/******************************* Bug Description and Comments *******************************/");
      System.out.println();
      for(int i = 0; i < n; i ++) {
      System.out.println(strBugDesc[i]);
      }
      System.out.println();
      System.out.println("/******************************* Bug Description and Comments *******************************/");
      }


      // Main funtion
      public static void main(String[] args) {
      TestJTable03 TestJTable03 = new TestJTable03(args);
      }
      }

      -- Sample Code --

            gsaab Georges Saab
            mmadhugisunw Mukund Madhugiri (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: