How do I prevent the JTable from clearing the selection when I right click on a cell?

Jesper Berglund

You can add a mouse listener to the table and manually set the selected row to the row the user clicked upon.


  ...

  jTable1.addMouseListener(new MouseAdapter(){
    public void mouseClicked(MouseEvent e) {
      if(SwingUtilities.isRigthMouseButton(e) &&
         e.getClickCount() == 2) {
        rightMouseButtonSingleClicked(e);
      }
    }
  });

  protected void rightMouseButtonSingleClicked(e) {
    int tClickedRow = jTable1.getRowAtPoint(e.getPoint);
    if(tClickedRow == -1)
      return;
    jTable1.setRowSelectionInterval(tClickedRow,tClickedRow);
  }

  ...
0 Comments  (click to add your comment)
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

About | Sitemap | Contact