• Post Reply Bookmark Topic Watch Topic
  • New Topic

JTable and CellEditor  RSS feed

 
Alex Kravets
Ranch Hand
Posts: 476
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Thomas Suer
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).]
 
Alex Kravets
Ranch Hand
Posts: 476
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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(){
^
 
turgay
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does anybody know a possibility for automaticly setting all entries in a cell in the JTable selected when clicking in a cell?
turgay
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!