diff --git a/src/me/drton/flightplot/FieldsListDialog.java b/src/me/drton/flightplot/FieldsListDialog.java index bbbbfbd..daad1f9 100644 --- a/src/me/drton/flightplot/FieldsListDialog.java +++ b/src/me/drton/flightplot/FieldsListDialog.java @@ -41,6 +41,29 @@ public void actionPerformed(ActionEvent e) { onClose(); } }, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); + + + // search a item when first character is pressed + fieldsTable.addKeyListener(new KeyAdapter() { + public void keyPressed(KeyEvent e) { + + if ( e.getKeyCode() >= KeyEvent.VK_A && e.getKeyCode() <= KeyEvent.VK_Z ) { + + char key = e.getKeyChar(); + + for (int i = fieldsTableModel.getRowCount() - 1; i >= 0; i--) { + String value = (String) fieldsTableModel.getValueAt(i, 0); + if (value != null && value.toUpperCase().startsWith(String.valueOf(key).toUpperCase())) { + fieldsTable.getSelectionModel().clearSelection(); + fieldsTable.getColumnModel().getSelectionModel().clearSelection(); + fieldsTable.changeSelection(i, 0, false, false); + + } + } + } + } + }); + } private void onClose() { diff --git a/src/me/drton/flightplot/LogInfo.java b/src/me/drton/flightplot/LogInfo.java index 41d4729..0685afa 100644 --- a/src/me/drton/flightplot/LogInfo.java +++ b/src/me/drton/flightplot/LogInfo.java @@ -4,6 +4,7 @@ import javax.swing.*; import javax.swing.table.DefaultTableModel; +import java.awt.event.*; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.*; @@ -26,6 +27,24 @@ public LogInfo() { mainFrame.pack(); dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS"); dateFormat.setTimeZone(TimeZone.getTimeZone("GMT")); + parametersTable.requestFocus(); + + // search a item when first character is pressed + parametersTable.addKeyListener(new KeyAdapter() { + public void keyPressed(KeyEvent e) { + + char key = e.getKeyChar(); + + for(int i = parametersTableModel.getRowCount() - 1 ; i >= 0 ; i--){ + String value = (String)parametersTableModel.getValueAt(i, 0); + if (value != null && value.toUpperCase().startsWith(String.valueOf(key).toUpperCase())) { + parametersTable.getSelectionModel().clearSelection(); + parametersTable.getColumnModel().getSelectionModel().clearSelection(); + parametersTable.changeSelection(i,0,false,false); + } + } + } + }); } public JFrame getFrame() {