-
Bug
-
Resolution: Not an Issue
-
P3
-
None
-
1.3.0, 1.4.0
-
x86, sparc
-
solaris_8, windows_nt
Name: krT82822 Date: 09/29/99
Before 1.3 beta, fireTableDataChanged() kept the selected lines.
Now, the behavior is different, the whole selection is lost.
------------
9/29/99 eval1127@eng -- setNumRows() deprecated, so tried tablemodel.removeRow(), followed by fireTableDataChanged...sure enough, selection lost.
Previous bugs seemed to deal with this, but can't find one that's still open.
Using variant of test case from bug # 4267264:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.table.*;
public class TestTable {
public static void main( String[] argv ) {
JFrame frame = new JFrame( "List TestTable" );
frame.addWindowListener( new WindowAdapter(){
public void windowClosing( WindowEvent e ){
System.exit( 0 );}});
final DefaultTableModel model = new DefaultTableModel( 0, 2 );
model.addRow (new Object[] {"R1", "r1"});
model.addRow (new Object[] {"R2", "r2"});
model.addRow (new Object[] {"R3", "r3"});
final JTable table = new JTable( model );
JButton button = new JButton( "get selection Indexes" );
JButton button0 = new JButton( "setNumRows( 0 )" );
JButton button1 = new JButton( "setNumRows( 1 )" );
button.addActionListener( new ActionListener() {
public void actionPerformed( ActionEvent e ) {
System.out.println ("anchorRow = "
+ table.getSelectionModel().getAnchorSelectionIndex());
System.out.println ("anchorCol = "
+ table.getColumnModel().getSelectionModel().getAnchorSelectionIndex());
}
});
button0.addActionListener( new ActionListener() {
public void actionPerformed( ActionEvent e ) {
model.setNumRows( 0 );
}
});
button1.addActionListener( new ActionListener() {
public void actionPerformed( ActionEvent e ) {
// model.setNumRows( 1 );
model.removeRow(2);
model.removeRow(1);
// model.fireTableDataChanged(); // this makes selection get lost
}
});
frame.getContentPane().setLayout( new GridLayout( 4, 1 ) );
frame.getContentPane().add( table );
frame.getContentPane().add( button );
frame.getContentPane().add( button0 );
frame.getContentPane().add( button1 );
frame.pack();
frame.show();
}
}
(Review ID: 95906)
======================================================================
- duplicates
-
JDK-4468714 fireTableDataChanged() makes the slected row unselected.
-
- Closed
-