Win a copy of The Way of the Web Tester: A Beginner's Guide to Automating Tests this week in the Testing forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JTable + Activating EditMode by cursorkeys

Roy Munson
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello !
I�ve got the following problem:
I wrote a JTable class, where the editmode of the table should be activated by the cursor up/down keys. To achieve this, I "overloaded" the valueChanged ( ListSelectionEvent le ) method,
which is used to manage changements in the selection of the tree.
Then I wanted the TextField to get the focus and used the requestFocus method.
The problem that occurs is, that the request of the focus seem to work only every second line, or to be more precisely, every second cursor down key. Here�s the code:
import javax.swing.*;
import javax.swing.event.*;
public class MyTable extends JTable {
public MyTable () {
super ( 5, 5 );

// Diese Methode wird �berlagert, um ein spezielles
// Verhalten beim Anw�hlen von Zellen zu gew�hrleisten,
// es soll per Tastatur in den EditMode gewechselt werden.
public void valueChanged ( ListSelectionEvent le ) {
System.out.println("valueChanged Methode !");
// valueChanged wird beim ersten Zeichen ebenfalls durchlaufen,
// daher muss dieser Fall hier abgefangen werden.

if ( getSelectedRow() != -1 ) {
editCellAt ( getSelectedRow(), getSelectedColumn () );
getEditorComponent().requestFocus ();
super.valueChanged ( le );
It would very nice, if anyone can help with this problem, the real example is greater and owns a own TableModel, I�ve extracted the important positions.
Wolfgang K.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic