-
Bug
-
Resolution: Won't Fix
-
P5
-
1.3.1_06, 1.4.0_01, 1.4.1_02, 1.4.2, 6
-
generic, x86
-
generic, windows_2000
Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-2172571 | 1.4-pool | Unassigned | P5 | Closed | Won't Fix |
Name: jk109818 Date: 04/22/2003
FULL PRODUCT VERSION :
java version "1.4.0_01"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0_01-b03)
Java HotSpot(TM) Client VM (build 1.4.0_01-b03, mixed mode)
FULL OPERATING SYSTEM VERSION :
Microsoft Windows 2000 [Version 5.00.2195]
EXTRA RELEVANT SYSTEM CONFIGURATION :
hey, is³s a quite simple program, isn³t it ?
A DESCRIPTION OF THE PROBLEM :
You get a Nullpointer exception, even if ce != null,
so it is an internal problem. It happens only, when
isCellEditable returns false.
What I wanted to do, is a fine text-input in a JTable
and to keep the entered data (without clicking another
row !), when I lose the focus (e.g. by clicking a button
or a checkbox). So I need this FocusListener.
I simply called makeTableGood() on all my tables. But it
seems that I have to distinguish on the editability
of the table (or even cell).
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. comple NPE.java
2. select a table-row
3. press a button
EXPECTED VERSUS ACTUAL BEHAVIOR :
You get a Nullpointer exception, even if ce != null,
so it is an internal problem. It happens only, when
isCellEditable returns false.
What kind of TableCellEditor does this cell then have ?
ERROR MESSAGES/STACK TRACES THAT OCCUR :
FocusListener: focusLost
java.lang.NullPointerException
at javax.swing.JTable$GenericEditor.stopCellEditing(Unknown Source)
at NPE$5.focusLost(NPE.java:104)
at java.awt.AWTEventMulticaster.focusLost(Unknown Source)
at java.awt.Component.processFocusEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.KeyboardFocusManager.redispatchEvent(Unknown Source)
at java.awt.DefaultKeyboardFocusManager.typeAheadAssertions(Unknown Sour
ce)
at java.awt.DefaultKeyboardFocusManager.dispatchEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.text.*;
import javax.swing.event.*;
import javax.swing.table.*;
import java.util.Vector;
public class NPE extends JFrame // sent to java.sun.com, Mon,
02/19/2003
{
JButton buttonUp, buttonDown, buttonNew;
JPanel panelButtons;
JTable table;
public NPE()
{
super("Null Pointer Exception");
Container contentPane = getContentPane();
Vector rowData = new Vector();
Vector row0 = new Vector();
Vector row1 = new Vector();
Vector row2 = new Vector();
row0.add("one"); row0.add("un");
row1.add("two"); row1.add("dos");
row2.add("three"); row2.add("tres");
rowData.add(row0); rowData.add(row1); rowData.add(row2);
Vector colNames = new Vector();
colNames.add("English"); colNames.add("Spanish");
table = new JTable(rowData, colNames) {
public boolean isCellEditable(int row, int col)
{
return false;
// true in the case of new-button
}
};
makeTableGood(table);
JScrollPane scrollPane = new JScrollPane(table);
buttonUp = new JButton("Up");
buttonDown = new JButton("Down");
buttonNew = new JButton("New");
panelButtons = new JPanel();
panelButtons.add(buttonUp);
panelButtons.add(buttonDown);
//panelButtons.add(buttonNew);
buttonUp.addActionListener( new ActionListener() {
public void actionPerformed(ActionEvent e)
{
int row = table.getSelectedRow();
int rowCount = table.getRowCount();
if (rowCount >= 2 && row >= 1) {
DefaultTableModel dm =
(DefaultTableModel) table.getModel();
dm.moveRow(row, row, row-1);
table.changeSelection(row-1, 0,
false, false);
}
}
});
buttonDown.addActionListener( new ActionListener() {
public void actionPerformed(ActionEvent e)
{
int row = table.getSelectedRow();
int rowCount = table.getRowCount();
if (rowCount >= 2 && row >= 0 && row <
rowCount-1) {
DefaultTableModel dm =
(DefaultTableModel) table.getModel();
dm.moveRow(row, row, row+1);
table.changeSelection(row+1, 0,
false, false);
}
}
});
buttonNew.addActionListener( new ActionListener() {
public void actionPerformed(ActionEvent e)
{
DefaultTableModel dm =
(DefaultTableModel) table.getModel();
Vector v = new Vector();
v.add(null);
v.add(null);
dm.addRow(v);
}
});
contentPane.setLayout(new BorderLayout());
contentPane.add(scrollPane, BorderLayout.CENTER);
contentPane.add(panelButtons, BorderLayout.SOUTH);
}
private void makeTableGood(final JTable table)
{
table.addFocusListener( new FocusListener() {
public void focusLost(FocusEvent e)
{
System.out.println("FocusListener: focusLost");
int row = table.getSelectedRow();
int colCount = table.getColumnCount();
if (row >= 0) {
for (int col=0; col<colCount; col++) {
TableCellEditor ce =
table.getCellEditor(row, col);
if (ce != null) {
ce.stopCellEditing
(); // gives Null-Pointer-Exception !?!
} // only if isCellEditable() returns false
}
}
}
public void focusGained(FocusEvent e)
{
}
});
}
public static void main(String[] args)
{
NPE frame = new NPE();
frame.setDefaultCloseOperation( EXIT_ON_CLOSE );
frame.pack();
frame.setVisible(true);
}
}
---------- END SOURCE ----------
CUSTOMER WORKAROUND :
it seems that I have to distinguish on the editability
of the table (or even cell).
(Review ID: 181505)
======================================================================
FULL PRODUCT VERSION :
java version "1.4.0_01"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0_01-b03)
Java HotSpot(TM) Client VM (build 1.4.0_01-b03, mixed mode)
FULL OPERATING SYSTEM VERSION :
Microsoft Windows 2000 [Version 5.00.2195]
EXTRA RELEVANT SYSTEM CONFIGURATION :
hey, is³s a quite simple program, isn³t it ?
A DESCRIPTION OF THE PROBLEM :
You get a Nullpointer exception, even if ce != null,
so it is an internal problem. It happens only, when
isCellEditable returns false.
What I wanted to do, is a fine text-input in a JTable
and to keep the entered data (without clicking another
row !), when I lose the focus (e.g. by clicking a button
or a checkbox). So I need this FocusListener.
I simply called makeTableGood() on all my tables. But it
seems that I have to distinguish on the editability
of the table (or even cell).
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. comple NPE.java
2. select a table-row
3. press a button
EXPECTED VERSUS ACTUAL BEHAVIOR :
You get a Nullpointer exception, even if ce != null,
so it is an internal problem. It happens only, when
isCellEditable returns false.
What kind of TableCellEditor does this cell then have ?
ERROR MESSAGES/STACK TRACES THAT OCCUR :
FocusListener: focusLost
java.lang.NullPointerException
at javax.swing.JTable$GenericEditor.stopCellEditing(Unknown Source)
at NPE$5.focusLost(NPE.java:104)
at java.awt.AWTEventMulticaster.focusLost(Unknown Source)
at java.awt.Component.processFocusEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.KeyboardFocusManager.redispatchEvent(Unknown Source)
at java.awt.DefaultKeyboardFocusManager.typeAheadAssertions(Unknown Sour
ce)
at java.awt.DefaultKeyboardFocusManager.dispatchEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.text.*;
import javax.swing.event.*;
import javax.swing.table.*;
import java.util.Vector;
public class NPE extends JFrame // sent to java.sun.com, Mon,
02/19/2003
{
JButton buttonUp, buttonDown, buttonNew;
JPanel panelButtons;
JTable table;
public NPE()
{
super("Null Pointer Exception");
Container contentPane = getContentPane();
Vector rowData = new Vector();
Vector row0 = new Vector();
Vector row1 = new Vector();
Vector row2 = new Vector();
row0.add("one"); row0.add("un");
row1.add("two"); row1.add("dos");
row2.add("three"); row2.add("tres");
rowData.add(row0); rowData.add(row1); rowData.add(row2);
Vector colNames = new Vector();
colNames.add("English"); colNames.add("Spanish");
table = new JTable(rowData, colNames) {
public boolean isCellEditable(int row, int col)
{
return false;
// true in the case of new-button
}
};
makeTableGood(table);
JScrollPane scrollPane = new JScrollPane(table);
buttonUp = new JButton("Up");
buttonDown = new JButton("Down");
buttonNew = new JButton("New");
panelButtons = new JPanel();
panelButtons.add(buttonUp);
panelButtons.add(buttonDown);
//panelButtons.add(buttonNew);
buttonUp.addActionListener( new ActionListener() {
public void actionPerformed(ActionEvent e)
{
int row = table.getSelectedRow();
int rowCount = table.getRowCount();
if (rowCount >= 2 && row >= 1) {
DefaultTableModel dm =
(DefaultTableModel) table.getModel();
dm.moveRow(row, row, row-1);
table.changeSelection(row-1, 0,
false, false);
}
}
});
buttonDown.addActionListener( new ActionListener() {
public void actionPerformed(ActionEvent e)
{
int row = table.getSelectedRow();
int rowCount = table.getRowCount();
if (rowCount >= 2 && row >= 0 && row <
rowCount-1) {
DefaultTableModel dm =
(DefaultTableModel) table.getModel();
dm.moveRow(row, row, row+1);
table.changeSelection(row+1, 0,
false, false);
}
}
});
buttonNew.addActionListener( new ActionListener() {
public void actionPerformed(ActionEvent e)
{
DefaultTableModel dm =
(DefaultTableModel) table.getModel();
Vector v = new Vector();
v.add(null);
v.add(null);
dm.addRow(v);
}
});
contentPane.setLayout(new BorderLayout());
contentPane.add(scrollPane, BorderLayout.CENTER);
contentPane.add(panelButtons, BorderLayout.SOUTH);
}
private void makeTableGood(final JTable table)
{
table.addFocusListener( new FocusListener() {
public void focusLost(FocusEvent e)
{
System.out.println("FocusListener: focusLost");
int row = table.getSelectedRow();
int colCount = table.getColumnCount();
if (row >= 0) {
for (int col=0; col<colCount; col++) {
TableCellEditor ce =
table.getCellEditor(row, col);
if (ce != null) {
ce.stopCellEditing
(); // gives Null-Pointer-Exception !?!
} // only if isCellEditable() returns false
}
}
}
public void focusGained(FocusEvent e)
{
}
});
}
public static void main(String[] args)
{
NPE frame = new NPE();
frame.setDefaultCloseOperation( EXIT_ON_CLOSE );
frame.pack();
frame.setVisible(true);
}
}
---------- END SOURCE ----------
CUSTOMER WORKAROUND :
it seems that I have to distinguish on the editability
of the table (or even cell).
(Review ID: 181505)
======================================================================
- backported by
-
JDK-2172571 NullPointerException inside of TableCellEditor.stopCellEditing
-
- Closed
-