[Logo]
Forums Register Login
JTable and CellEditor
Hi,
I am trying to use CellEditor in my JTable, so when a user changes one of the fields, I will know about it.
This is what I did:
public void addCellEditorListerner(JTable table){
table.getCellEditor().addCellEditorListener(new CellEditorListener(){
public void editingStopped(ChangeEvent e){
System.out.println("Value Changed");
}
public void editingCanceled(ChangeEvent e){
}
});
This compiles fine, but when I run my applet, I get NullPointerException.
Do I have to do some preliminary set up of my table in order to regiser CellEditor?
thanks,
Alex
Of course the table's reference mustn't be null.
But to answer your question we first need to have more code and/or a more detailed error message, like a stack trace...
For instance, what cell editor do you use? Did you write your own editor? If not you should try to add your listener to the DEFAULT editor instead of editor:
<code>table.getDefaultEditor().addCellEditorListener(new CellEditorListener()...</code>
Tom
[This message has been edited by Thomas Suer (edited October 17, 2001).]
[This message has been edited by Thomas Suer (edited October 17, 2001).]
In Java API, I couldn't find DefaultEditor class, I did find DefaultCellEditor, but constructor of this class takes as a parameter either a JComboBox or JTextField. I did try to use DefaultEditor as:
public void addCellEditorListerner(JTable table){
try{
table.getDefaultEditor().addCellEditorListener(new CellEditorListener(){
public void editingStopped(ChangeEvent e){
System.out.println("Value Changed");
}
public void editingCanceled(ChangeEvent e){
}
});
}
catch(NullPointerException exp){
exp.printStackTrace();
}
}
but got this error:
PursAppletGB.java:518: getDefaultEditor(java.lang.Class) in javax.swing.JTable c
annot be applied to ()
table.getDefaultEditor().addCellEditorListener(new CellEditorLis
tener(){
^
Does anybody know a possibility for automaticly setting all entries in a cell in the JTable selected when clicking in a cell?
turgay
Wink, wink, nudge, nudge, say no more ... https://richsoil.com/cards



All times above are in ranch (not your local) time.
The current ranch time is
Nov 19, 2017 00:13:07.