I've been searching the web.. and i found the building blocks for manipulating the keybindings for JTable, the input maps, action maps
i manage to disable the TAB key binding for JTable(below the code, which i also got somewhere in the web) .. which selects the next cell..
my problem is .. the arrow keys navigates the Table with no problem "IF" the cell is not editable/editing.. ofcourse the purpose of arrow keys for the cell is(as far as I'm concern) is bounded on the JTextFields(as per cell in the JTable), moving the caret across the characters
i really dont know how to put everything i know so far together to MAP the LEFT and RIGHT arrow keys to navigate from previous and next cell disregarding the editing just like how TAB and SHIFT+TAB does.. i dont even know where to put these "selectPreviousColumnCell" and "selectNextColumnCell"..
those things were here and here
i got the idea of VK_UP for "Table.selectPreviousRow" and VK_DOWN "Table.selectNextRow"... i just lost my self trying to find how to bind
"selectPreviousColumnCell" to VK_LEFT and "selectNextColumnCell" to VK_RIGHT.. even the cell is editing,, just like how TAB and SHIT+TAB binding does .. disregarding the editing and instead moves from cell to cell
import javax.swing.*; import java.awt.*; import java.awt.event.*; import javax.swing.table.*; class Sample { private JFrame frame; private JPanel panel; private JTable table; public Sample() { initComponents(); } public void initComponents() { frame = new JFrame(); panel = new JPanel(); table = new JTable(50, 5); ActionMap am = table.getActionMap(); am.put("selectPreviousColumnCell", new PreviousFocusHandler()); am.put("selectNextColumnCell", new NextFocusHandler()); table.setColumnSelectionAllowed(true); table.setPreferredSize(new Dimension(400, 400)); panel.add(table); frame.getContentPane().add(panel); frame.setSize(400, 400); frame.setLocationRelativeTo(null); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); } public class PreviousFocusHandler extends AbstractAction { public void actionPerformed(ActionEvent evt) { } } public class NextFocusHandler extends AbstractAction { public void actionPerformed(ActionEvent evt) { } } public static void main(String[] args) { new Sample(); } }
- i want to know the Table defaults for keybindings or keyboard strokes which I cant find on LAF defaults.. there is this "Table.selectPreviousRow" and "Table.selectNextRow" , i dont know if there are "Table.selectPreviousCell" and "Table.selectNextCell", and how to Map it properly using InputMap and ActionMap. Thank in advance again!!
--- Update ---
i found something made by Rob Camickr.. which seems very usefull i just dont know where to put this part in my code
Table Tabbing Java Tips Weblog