-
Bug
-
Resolution: Not an Issue
-
P4
-
None
-
6
-
x86
-
windows_xp
FULL PRODUCT VERSION :
java version "1.6.0"
Java(TM) SE Runtime Environment (build 1.6.0-b105)
Java HotSpot(TM) Client VM (build 1.6.0-b105, mixed mode, sharing)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP [Version 5.1.2600]
A DESCRIPTION OF THE PROBLEM :
The height of a JTable will not be updated after adding a new row to a DefaultTableModel-Object. Thus it is impossible to scroll to the new row in a JScrollPane.
Although the Method JTable.getCellRect returns the proper rectangle (a rectangle straight beneath the tables bottom), the method JTable.scrollRectToVisible only scrolls to the second-last row of the table (the bottom of the table before the insertion of the new row).
The same problem occurs with JRE 1.5.0.09
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Compile and run the following Program
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The last row of the table should be visible in the ScrollPane of the frame. The printed height of the table should grow after adding the new row. So the output in the second line should be an higher number than the number in the first row. The sum of the y-position and the height of the bounds of the tablecell should be equal to the second height of the table.
ACTUAL -
The last row of the table is not visible. The user must scroll to the last row using the scrollbars. The height of the table after adding a row is equal to the height before adding the row. The printed bounds of the cell lie outside the returned height of the table.
ERROR MESSAGES/STACK TRACES THAT OCCUR :
no error message.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
package test;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
public class Tabletest {
public static void main(String[] args) {
JFrame frame = new JFrame();
DefaultTableModel model = new DefaultTableModel(new String[]{"A", "B"}, 20);
JTable table = new JTable(model);
frame.add(new JScrollPane(table));
frame.setSize(200, 200);
frame.setVisible(true);
System.out.println(table.getHeight());
table.scrollRectToVisible(table.getCellRect(19, 0, true));
model.addRow(new String[]{"a", "b"});
System.out.println(table.getHeight());
System.out.println(table.getCellRect(20, 0, true));
table.scrollRectToVisible(table.getCellRect(20, 0, true));
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Sorry. No workaround...
java version "1.6.0"
Java(TM) SE Runtime Environment (build 1.6.0-b105)
Java HotSpot(TM) Client VM (build 1.6.0-b105, mixed mode, sharing)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP [Version 5.1.2600]
A DESCRIPTION OF THE PROBLEM :
The height of a JTable will not be updated after adding a new row to a DefaultTableModel-Object. Thus it is impossible to scroll to the new row in a JScrollPane.
Although the Method JTable.getCellRect returns the proper rectangle (a rectangle straight beneath the tables bottom), the method JTable.scrollRectToVisible only scrolls to the second-last row of the table (the bottom of the table before the insertion of the new row).
The same problem occurs with JRE 1.5.0.09
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Compile and run the following Program
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The last row of the table should be visible in the ScrollPane of the frame. The printed height of the table should grow after adding the new row. So the output in the second line should be an higher number than the number in the first row. The sum of the y-position and the height of the bounds of the tablecell should be equal to the second height of the table.
ACTUAL -
The last row of the table is not visible. The user must scroll to the last row using the scrollbars. The height of the table after adding a row is equal to the height before adding the row. The printed bounds of the cell lie outside the returned height of the table.
ERROR MESSAGES/STACK TRACES THAT OCCUR :
no error message.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
package test;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
public class Tabletest {
public static void main(String[] args) {
JFrame frame = new JFrame();
DefaultTableModel model = new DefaultTableModel(new String[]{"A", "B"}, 20);
JTable table = new JTable(model);
frame.add(new JScrollPane(table));
frame.setSize(200, 200);
frame.setVisible(true);
System.out.println(table.getHeight());
table.scrollRectToVisible(table.getCellRect(19, 0, true));
model.addRow(new String[]{"a", "b"});
System.out.println(table.getHeight());
System.out.println(table.getCellRect(20, 0, true));
table.scrollRectToVisible(table.getCellRect(20, 0, true));
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Sorry. No workaround...