Posted Monday, September 25, 2006 @ 03:00:03
thank you for your answer
i don't need setSurrendersFocusOnKeystroke = true for textfield.
But for combobox, i had to use it in order to change the cell value without using the mouse !
i want to use the jtable without the mouse . so i have to use setSurrendersFocusOnKeystroke = true to enter the combobox when pressing space ...
the problem is for this example :
i can' t select avalue from the combobox when i 'm not using setsurrendersfocusonkeystroke without using the mouse to enter the celleditor
but when i'm using the setsurrend... then try to change a value from a textfield WITHOUT using the mouse. you will see that the first key is for nothing ! ! !
here's the example:
import javax.swing.*;
import quick.dbtable.*;
import java.awt.event.KeyEvent;
import java.sql.*;
import java.util.Hashtable;
public class QuickTableFrame extends JFrame
{
public QuickTableFrame()
{
//set Frame properties
setSize(300,200);
setVisible(true);
//create a new quicktable
quick.dbtable.DBTable dBTable1 = new quick.dbtable.DBTable();
//add to frame
getContentPane().add(dBTable1);
//set the database driver to be used, we are using jdbc-odbc driver
dBTable1.setDatabaseDriver("sun.jdbc.odbc.JdbcOdbcDriver");
/*
set the jdbc url,"quicktabledemo" is the data source we have created
for the database
*/
dBTable1.setJdbcUrl("jdbc:odbc:quicktabledemo");
// set the select statement which should be used by the table
dBTable1.setSelectSql("select * from employee");
//to create the navigation bars for the table
dBTable1.createControlPanel();
dBTable1.enableTextOverwriteOnCellEdit = true;
KeyStroke enterKey = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER,0);
KeyStroke tab = KeyStroke.getKeyStroke(KeyEvent.VK_TAB, 0);
InputMap tableInputMap = dBTable1.getTable().getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
tableInputMap.put(enterKey, tableInputMap.get(tab));
dBTable1.getTable().setSurrendersFocusOnKeystroke(true);
try
{
//connect to database & create a connection
dBTable1.connectDatabase();
//fetch the data from database to fill the table
dBTable1.refresh();
}
catch(SQLException e)
{
e.printStackTrace();
}
catch(ClassNotFoundException e)
{
e.printStackTrace();
}
Column c = dBTable1.getColumn(3);
c.setPreferredWidth(60);
Hashtable h = new Hashtable();
h.put("Y", new Boolean(true));
h.put("N", new Boolean(false));
dBTable1.setCellComponent(c,Column.CHECKBOX_CELL,h);
c = dBTable1.getColumn(2);
h = new Hashtable();
h.put("V","Vv");
h.put("A","Aa");
h.put("M","Mm");
dBTable1.setCellComponent(c,Column.COMBOBOX_CELL,h);
dBTable1.getColumn(0).setReadOnly(false);
dBTable1.getColumn(1).setReadOnly(false);
dBTable1.getColumn(2).setReadOnly(false);
dBTable1.getColumn(3).setReadOnly(false);
}
public static void main(String[] args)
{
//create a new table frame
QuickTableFrame myframe = new QuickTableFrame();
}
}
thank you
--------------------
Olivier