can cell in jdbtable get focus instantly after press Enter key


2004-04-17 04:14:21 PM
jbuilder10
can cell in jdbtable get focus instantly after press Enter key?
it can be achieved as a plain table like this:
-------------------------------------------------------------------
package untitled1;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import com.borland.dbswing.*;
public class test
extends JFrame {
JdbTable table = new JdbTable(5, 5);
Action myEnterAction = new AbstractAction() {
public void actionPerformed(ActionEvent e) {
int rowCount = table.getRowCount();
int colCount = table.getColumnCount();
if ( (rowCount <= 0) || (colCount <= 0)) {
return;
}
int row = table.getEditingRow();
int col = table.getEditingColumn();
if ( (row < 0) || (col < 0)) {
// if not in editing, start edit the selected row.
row = table.getSelectedRow();
col = table.getSelectedColumn();
if ( (row < 0) || (col < 0)) {
row = col = 0;
}
}
else {
// edit the "next" cell
if (col + 1 < colCount) {
col++;
}
else if (row + 1 < rowCount) {
row++;
col = 0;
}
else {
row = col = 0;
}
}
table.setRowSelectionInterval(row, row);
table.setColumnSelectionInterval(col, col);
table.editCellAt(row, col);
}
};
public test() {
try {
jbInit();
}
catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
test test = new test();
}
private void jbInit() throws Exception {
this.getContentPane().add(table, BorderLayout.CENTER);
KeyStroke enter_key = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0,
false);
table.getInputMap().put(enter_key, "ENTER");
table.getActionMap().put("ENTER", myEnterAction);
this.setSize(new Dimension(400, 300));
this.setVisible(true);
}
}
---------------------------------------------------------------------
but when i setdataset to table
it just went wrong
does anyone know how to do it another way?