-
Bug
-
Resolution: Fixed
-
P4
-
1.1.4
-
1.0.2
-
x86
-
windows_nt
Name: dgC58589 Date: 12/05/97
Although the SWING documentation notes that it is valid
to have a null table header, calling
setTableHeader(null) on a JTable causes a
NullPointerException.
Here is the info...I'm running on NT 4.0 with JDK 1.1.4 and
JFC 0.6.1. I just found out that 1.1.5 is available so I'll install
that and see if it helps, but the errors look like they are JFC
specific.
Incidentally, I have discovered another possible bug. To
demonstrate the second bug, comment out the setTableHeader()
line, and run it again. Select an item in the list, and then press the
button. What I expect it to do is move the selected row down
one position. JTable.moveRow() works the first time, if the row
you're trying to move is row #0. But if you click the button a second
time to move the row again, or if you select a different row and
try to move it, it blows up with:
Exception occurred during event dispatching:
java.lang.ArrayIndexOutOfBoundsException: Array index out of range: 1
at com.sun.java.swing.table.DefaultTableModel.moveRow(DefaultTableModel.
java:819)
at com.sun.java.swing.JTable.moveRow(JTable.java:1233)
(etc...)
The workaround I came up with for this is to remove the selected row
and reinsert it at the new position. This works fine in all cases.
Please let me know if you need any other info.
Cheers,
Mark
----------------- here is the test code --------------------
import java.awt.*;
import java.awt.event.*;
import com.sun.java.swing.*;
import com.sun.java.swing.border.*;
//
//
// Main
//
//
public class Main extends Frame implements ActionListener
{
private JButton down;
private JTable jt;
public Main()
{
super();
setLayout(new BorderLayout(0, 0));
jt = new JTable();
jt.setAutoCreateColumnsFromModel(false);
jt.setColumnSelectionAllowed(false);
jt.setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN);
jt.setShowGrid(false);
jt.sizeColumnsToFit(true);
jt.setTableHeader(null); // <-- here is the offending line
jt.addColumn("", 100,
new DefaultCellRenderer(new JLabel("")),
null, null);
JScrollPane scrollPane = JTable.createScrollPaneForTable(jt);
scrollPane.setAlignmentX(LEFT_ALIGNMENT);
scrollPane.setAlignmentY(TOP_ALIGNMENT);
scrollPane.setBorder(new BevelBorder(BevelBorder.LOWERED));
add("Center", scrollPane);
setSize(300, 300);
String[] data = {"zero", "one", "two", "three", "four", "five", "six",
"seven", " "};
Object row[] = new Object[1];
for(int i = 0; i < data.length; i++)
{
row[0] = data[i];
jt.addRow(row);
}
down = new JButton("move item down");
add("South", down);
down.addActionListener(this);
}
public static void main(String args[])
{
Main app = new Main();
app.show();
}
public void actionPerformed(ActionEvent evt)
{
if(evt.getSource() == down)
{
int i = jt.getSelectedRow();
if(i < 0 || i > (jt.getRowCount() - 2)) return;
jt.moveRow(i, i, i + 1); // <-- it blows up here too
jt.getSelectionModel().setSelectionInterval(i + 1, i + 1);
}
}
}
(Review ID: 21432)
======================================================================