-
Bug
-
Resolution: Unresolved
-
P4
-
None
-
6
-
x86
-
windows_xp
FULL PRODUCT VERSION :
1.6.0_02-b06
ADDITIONAL OS VERSION INFORMATION :
Windows XP [Version 5.1.2600]
A DESCRIPTION OF THE PROBLEM :
When clicking on the intercell spacing, JTable starts the TableCellEditor on this cell. When clicking again, it calls stopCellEditing and activates the TableCellEditor again.
The editor should not start when clicking the intercell spacing.
Complex TableCellEditors (like the JColorChooser dialog in TableDialogEditDemo example [1]) using ActionListener or MouseListener will not show up correctly, because clicking on the intercell spacing means clicking outside the editor component and thus there won't be any ActionEvent or MouseEvent.
This issue leads to minor user inconvenience.
[1] http://java.sun.com/docs/books/tutorial/uiswing/components/table.html#editor
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Start the attached example application. It uses a JTable with a 50px wide intercell spacing to demonstrate the issue.
2. Click on the renderer label. Notice that the editor appears and turns instantly to green as it gets a mousePressed event.
3. Click "stop editor" button and click on the left or right white intercell spacing. Notice that the editor appears but it remains red because it doesn't get a mousePressed event.
The issue is also reproducible when using default intercell spacing, but it's harder to hit the 1px intercell spacing. It's also reproducible in the JColorChooser example mentioned above: editor becomes activated, but no dialog appears.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
When clicking on the intercell spacing in step 3, I'd expect that nothing happens.
ACTUAL -
When clicking on the intercell spacing in step 3, the TableCellEditor becomes activated.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.AbstractCellEditor;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JTable;
import javax.swing.event.CellEditorListener;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableCellEditor;
import javax.swing.table.TableModel;
public class TableEditorTest {
final boolean wideIntercellSpacing = true;
final TableCellEditor editor = new MyEditor();
public TableEditorTest() {
// single cell
TableModel model = new DefaultTableModel(new String[][] {{"Click this cell"}}, new String[] { "column" });
// table with 30px row
JTable table = new JTable(model);
table.getColumnModel().getColumn(0).setCellEditor(editor);
table.setRowHeight(30);
// set large intercell spacing
if (wideIntercellSpacing) {
table.setIntercellSpacing(new Dimension(50, 10));
}
System.out.println("intercell width: " + table.getIntercellSpacing().getWidth());
System.out.println("intercell height: " + table.getIntercellSpacing().getHeight());
// button to stop TableCellEditor
JButton stopEdit = new JButton("stop editor");
stopEdit.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
editor.stopCellEditing();
}
});
// show table and button in frame
JFrame frame = new JFrame();
frame.setLayout(new BorderLayout());
frame.add(table, BorderLayout.CENTER);
frame.add(stopEdit, BorderLayout.SOUTH);
frame.setLocationByPlatform(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(300, 100);
frame.setVisible(true);
}
class MyEditor extends AbstractCellEditor implements TableCellEditor {
JButton cellButton = new JButton();
Object value;
MyEditor() {
cellButtonDefault();
// test is passed when cellButton gets a mousePressed event
cellButton.addMouseListener(new MouseAdapter() {
public void mousePressed(MouseEvent e) {
cellButton.setBackground(Color.GREEN);
cellButton.setText("OK: editor got mousePressed");
}
});
}
public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
this.value = value;
return cellButton;
}
public Object getCellEditorValue() {
return value;
}
public void cancelCellEditing() {
System.out.println("cancelCellEditing");
cellButtonDefault();
super.cancelCellEditing();
}
public boolean stopCellEditing() {
System.out.println("stopCellEditing");
cellButtonDefault();
return super.stopCellEditing();
}
public void addCellEditorListener(CellEditorListener l) {
System.out.println("addCellEditorListener: " + l);
super.addCellEditorListener(l);
}
public void removeCellEditorListener(CellEditorListener l) {
System.out.println("removeCellEditorListener: " + l);
super.removeCellEditorListener(l);
}
void cellButtonDefault() {
// default: test failed
cellButton.setBackground(Color.RED);
cellButton.setText("Fail: no mousePressed event");
}
}
public static void main(String[] args) {
new TableEditorTest();
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Setting intercell spacing to 0px solves the issue, but introduces visual defects (grid not being shown correctly).
Another possibility for complex TableCellEditors: When the editor is being activated, getTableCellEditorComponent() is called. Thus it's possible to put all open-dialog-code into this method and not use any ActionListener/MouseListener.
1.6.0_02-b06
ADDITIONAL OS VERSION INFORMATION :
Windows XP [Version 5.1.2600]
A DESCRIPTION OF THE PROBLEM :
When clicking on the intercell spacing, JTable starts the TableCellEditor on this cell. When clicking again, it calls stopCellEditing and activates the TableCellEditor again.
The editor should not start when clicking the intercell spacing.
Complex TableCellEditors (like the JColorChooser dialog in TableDialogEditDemo example [1]) using ActionListener or MouseListener will not show up correctly, because clicking on the intercell spacing means clicking outside the editor component and thus there won't be any ActionEvent or MouseEvent.
This issue leads to minor user inconvenience.
[1] http://java.sun.com/docs/books/tutorial/uiswing/components/table.html#editor
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Start the attached example application. It uses a JTable with a 50px wide intercell spacing to demonstrate the issue.
2. Click on the renderer label. Notice that the editor appears and turns instantly to green as it gets a mousePressed event.
3. Click "stop editor" button and click on the left or right white intercell spacing. Notice that the editor appears but it remains red because it doesn't get a mousePressed event.
The issue is also reproducible when using default intercell spacing, but it's harder to hit the 1px intercell spacing. It's also reproducible in the JColorChooser example mentioned above: editor becomes activated, but no dialog appears.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
When clicking on the intercell spacing in step 3, I'd expect that nothing happens.
ACTUAL -
When clicking on the intercell spacing in step 3, the TableCellEditor becomes activated.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.AbstractCellEditor;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JTable;
import javax.swing.event.CellEditorListener;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableCellEditor;
import javax.swing.table.TableModel;
public class TableEditorTest {
final boolean wideIntercellSpacing = true;
final TableCellEditor editor = new MyEditor();
public TableEditorTest() {
// single cell
TableModel model = new DefaultTableModel(new String[][] {{"Click this cell"}}, new String[] { "column" });
// table with 30px row
JTable table = new JTable(model);
table.getColumnModel().getColumn(0).setCellEditor(editor);
table.setRowHeight(30);
// set large intercell spacing
if (wideIntercellSpacing) {
table.setIntercellSpacing(new Dimension(50, 10));
}
System.out.println("intercell width: " + table.getIntercellSpacing().getWidth());
System.out.println("intercell height: " + table.getIntercellSpacing().getHeight());
// button to stop TableCellEditor
JButton stopEdit = new JButton("stop editor");
stopEdit.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
editor.stopCellEditing();
}
});
// show table and button in frame
JFrame frame = new JFrame();
frame.setLayout(new BorderLayout());
frame.add(table, BorderLayout.CENTER);
frame.add(stopEdit, BorderLayout.SOUTH);
frame.setLocationByPlatform(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(300, 100);
frame.setVisible(true);
}
class MyEditor extends AbstractCellEditor implements TableCellEditor {
JButton cellButton = new JButton();
Object value;
MyEditor() {
cellButtonDefault();
// test is passed when cellButton gets a mousePressed event
cellButton.addMouseListener(new MouseAdapter() {
public void mousePressed(MouseEvent e) {
cellButton.setBackground(Color.GREEN);
cellButton.setText("OK: editor got mousePressed");
}
});
}
public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
this.value = value;
return cellButton;
}
public Object getCellEditorValue() {
return value;
}
public void cancelCellEditing() {
System.out.println("cancelCellEditing");
cellButtonDefault();
super.cancelCellEditing();
}
public boolean stopCellEditing() {
System.out.println("stopCellEditing");
cellButtonDefault();
return super.stopCellEditing();
}
public void addCellEditorListener(CellEditorListener l) {
System.out.println("addCellEditorListener: " + l);
super.addCellEditorListener(l);
}
public void removeCellEditorListener(CellEditorListener l) {
System.out.println("removeCellEditorListener: " + l);
super.removeCellEditorListener(l);
}
void cellButtonDefault() {
// default: test failed
cellButton.setBackground(Color.RED);
cellButton.setText("Fail: no mousePressed event");
}
}
public static void main(String[] args) {
new TableEditorTest();
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Setting intercell spacing to 0px solves the issue, but introduces visual defects (grid not being shown correctly).
Another possibility for complex TableCellEditors: When the editor is being activated, getTableCellEditorComponent() is called. Thus it's possible to put all open-dialog-code into this method and not use any ActionListener/MouseListener.