Tom Studer's Home Page
[ start | index | login ]
start > 2006-06-07 > 2

2006-06-07 #2

Created by tom. Last edited by tom, 5 years and 348 days ago. Viewed 420 times. #1
[edit] [rdf]
labels
attachments

Swing JTable right-mouse selection & popup menus

When requesting the popup menu on a table with no current selection it is sometimes convenient to have the table select the clicked row before poping up the menu.

This can be achieved using the following code:

table.addMouseListener(new MouseAdapter() {
    public void mousePressed(MouseEvent e) {
        if (e.getModifiers() == Event.META_MASK
                && getSelectedRowCount() == 0) {
            Point p = e.getPoint();
            int row = table.rowAtPoint(p);
            table.setRowSelectionInterval(row, row);
        }
    }
});
no comments | post comment
mouse_cartoon



< May 2012 >
SunMonTueWedThuFriSat
12345
6789101112
13141516171819
20212223242526
2728293031

snipsnap-help | More Help

Powered by SnipSnap 1.0b2-uttoxeter

Describe here what your SnipSnap is about!

Configure this box!

  1. Login in
  2. Click here: snipsnap-portlet-2
  3. Edit this box
snipsnap.org | Copyright 2000-2002 Matthias L. Jugel and Stephan J. Schmidt