-
Bug
-
Resolution: Fixed
-
P3
-
1.1.5
-
1.2.2
-
x86
-
windows_nt
Name: rk38400 Date: 04/13/98
getSelectedRow() / getSelectedColumn will return the
last selected row index / column index when I click
on the empty area in the table, instead of -1 (which
is what I am expacting to be return). The reason is
when I do right mouse click on a row, I will show
the popup menu. If I do right mouse click on the
empty area, I do not show the popup menu. Thank in
advance for the help.
Helen
(Review ID: 26508)
======================================================================
Here's a sample to demonstrate the problem. Press the setNumRows( 3 ) button to clear out part of the list so that you can click on an empty area.
tom.santos@eng 1998-05-28
import com.sun.java.swing.*;
import com.sun.java.swing.table.*;
import java.awt.event.*;
import java.awt.*;
public class Test {
public static void main( String[] argv ) {
JFrame frame = new JFrame( "List Test" );
frame.addWindowListener( new WindowAdapter(){
public void windowClosing( WindowEvent e ){
System.exit( 0 );}});
final DefaultTableModel model = new DefaultTableModel( new Object[] { "One", "Two" }, 0 );
final JTable table = new JTable( model );
table.addMouseListener( new MouseAdapter() {
public void mousePressed( MouseEvent e ) {
System.out.println( "selectedRow: " + table.getSelectedRow() );
}
});
for ( int i = 0; i < 4; ++i ) {
model.addRow( new Object[] { "smatter", "chew" } );
model.addRow( new Object[] { "momynyms", "wentothustore" } );
model.addRow( new Object[] { "mungry", "squeet" } );
}
JButton button = new JButton( "setNumRows( 3 )" );
button.addActionListener( new ActionListener() {
public void actionPerformed( ActionEvent e ) {
model.setNumRows( 3 );
table.repaint();
}
});
frame.getContentPane().setLayout( new GridLayout( 2, 1 ) );
frame.getContentPane().add( table );
frame.getContentPane().add( button );
frame.pack();
frame.show();
}
}