This week's book giveaways are in the Scala and Android forums.
We're giving away four copies each of Machine Learning Systems: Designs that scale and Xamarin in Action: Creating native cross-platform mobile apps and have the authors on-line!
See this thread and this one for details.
Win a copy of Machine Learning Systems: Designs that scale this week in the Scala forum
or Xamarin in Action: Creating native cross-platform mobile apps in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JTable and CellEditor  RSS feed

 
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
 
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(){
^
 
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
 
Too many men are afraid of being fools - Henry Ford. Foolish tiny ad:
Rocket Oven Kickstarter - from the trailboss
https://coderanch.com/t/695773/Rocket-Oven-Kickstarter-trailboss
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!