• Post Reply Bookmark Topic Watch Topic
  • New Topic

Requesting Focus to next column in JTable  RSS feed

 
mohana konakanchi
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
JTable is not updating the recently edited cell, unless focus is changed from that cell.
Can any body explain me how to set focus to next column in same row, so that JTable will automatically update the current cell.
Sample code / good explanation is appreciated.
thanks in advance
Mohana
 
Laurent Leonard
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can force the edition to be stopped by using this :
TableCellEditor cell;
cell = myTable.getCellEditor(row, col);
if (cell != null)
{
cell.stopCellEditing();
}

------------------
Laurent Leonard
Laurent.Leonard@belgique.com
 
mohana konakanchi
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Thank you Leonard.
It's very help full solution for me. It's working fine.
Mohana
 
mohana konakanchi
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Leonard.
Above solution working fine. But some times it's thorowing the below exception.
In fact I am checking for cell != null before calling stopCellEditing() function. No idea why it's giving null pointer exception while calling this function.
Could you please help on this?

Exception occurred during event dispatching:
java.lang.NullPointerException
at javax.swing.JTable$GenericEditor.stopCellEditing(JTable.java:3295)
at eve.EVEApplet.actionPerformed(EVEApplet.java:733)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1450)
at javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(AbstractButton.java:1504)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:378)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:250)
at javax.swing.AbstractButton.doClick(AbstractButton.java:279)
at javax.swing.plaf.basic.BasicMenuItemUI$MouseInputHandler.mouseReleased(BasicMenuItemUI.ja
va:886)
at java.awt.Component.processMouseEvent(Component.java:3717)
at java.awt.Component.processEvent(Component.java:3546)
at java.awt.Container.processEvent(Container.java:1164)
at java.awt.Component.dispatchEventImpl(Component.java:2595)
at java.awt.Container.dispatchEventImpl(Container.java:1213)
at java.awt.Component.dispatchEvent(Component.java:2499)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:2451)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:2216)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:2125)
at java.awt.Container.dispatchEventImpl(Container.java:1200)
at java.awt.Window.dispatchEventImpl(Window.java:912)
at java.awt.Component.dispatchEvent(Component.java:2499)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:319)
at java.awt.EventDispatchThread.pumpOneEvent(EventDispatchThread.java:103)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:84)
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!