Results 1 to 10 of 10
Thread: JTable naviagation problem
- 07-14-2009, 03:08 PM #1
Member
- Join Date
- Mar 2009
- Posts
- 10
- Rep Power
- 0
JTable naviagation problem
Dear friends,
I have created a jtable and i want to change the enter key functionality to tab key. when i press enter the focus has to move to next column cell. the main thing is i also have custom cell editor and cell renderer of jtextfield.
if i use actionlistener or keylistener in celleditor in getTableCellEditorComponent() method, when i press enter it is firing as many rows available in the respective column. i spent two days on these. please some one help me out.
code looks like this.
setDefaultCloseOperation(EXIT_ON_CLOSE);
table = new JTable(4,4) ;
table.setCellSelectionEnabled(true);
TestRenderer trend = new TestRenderer();
TestEditor tedit = new TestEditor(this);
tcol = table.getColumnModel().getColumn(0);
tcol.setCellRenderer(trend);
tcol.setCellEditor(tedit);
tcol = table.getColumnModel().getColumn(1);
tcol.setCellRenderer(trend);
tcol.setCellEditor(tedit);
tcol = table.getColumnModel().getColumn(2);
tcol.setCellRenderer(trend);
tcol.setCellEditor(tedit);
tcol = table.getColumnModel().getColumn(3);
tcol.setCellRenderer(trend);
tcol.setCellEditor(tedit);
table.setSurrendersFocusOnKeystroke(true);
JScrollPane js = new JScrollPane();
js.setViewportView(table);
getContentPane().add(js);
setSize(400,500);
setVisible(true);
cell editor code is,
public Component getTableCellEditorComponent(JTable table,Object value,
boolean isSelected,int row,int column) {
if (value == null) {
setText("");
}
else{
setText(value.toString());
}
return this;
}
Thanks,
KhadareeLast edited by khadaree; 07-14-2009 at 03:13 PM.
- 07-14-2009, 09:58 PM #2
See Keyboard Operation for Tables for the default keyboard operations.
Then How to Use Key Bindings for how to change things according to your requirements.
- 07-14-2009, 10:13 PM #3
Unable to post code to this thread.
- 07-15-2009, 08:39 AM #4
Member
- Join Date
- Mar 2009
- Posts
- 10
- Rep Power
- 0
Hi hardwired,
I think you are not understood my problem. I want the enter key work like a tab key in Jtable. I have tried adding the actionlistener to the JTextfield in CustomCellEditor and I have tried using Action classes,InputMap() and ActionMaps also. but when i press enter these methods are firing more than one time and the result is random focus in the jtable.
Please some one help me out.
Thanks,
Khadaree
- 07-15-2009, 08:56 AM #5
Member
- Join Date
- Mar 2009
- Posts
- 10
- Rep Power
- 0
solved the problem by using the following code,
table.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCU SED_COMPONENT).
put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0),
"selectNextColumnCell");
Thanks,
Khadree.
- 07-16-2009, 08:44 AM #6
Senior Member
- Join Date
- Jul 2009
- Posts
- 1,143
- Rep Power
- 5
Instead of hardcoding the "selectNextColumnCell" which means you first have to know what string to use, the easier way is to just change the InputMap using the KeyStroke of the Tab key.I want the enter key work like a tab key in Jtable
An example of this approach is found here:
"tips4java-wordpress-com"
Then search for "Key Bindings"
(I can't post real links yet)
- 07-16-2009, 01:52 PM #7
Here's the code example I was unable to post the other day. Fubarable suggested attatching it in a zip file.
-
Hardwired: What happens when you try to post code here? Perhaps the forum software has a bug that needs to be addressed?
- 07-16-2009, 07:23 PM #9
What happens when you try to post code here?
I've narrowed it down to this line:
ActionM a p actionM a p = target.getActionMap();
If I remove the spaces in the "M a p" parts of the string I get a 404 — page_not_found error when I press the "Preview Post" button.
-
Similar Threads
-
JTable problem
By sandeepsai39 in forum New To JavaReplies: 2Last Post: 06-27-2009, 06:15 AM -
Problem With AI and JTable
By elad_bj in forum New To JavaReplies: 8Last Post: 04-20-2009, 02:24 PM -
JTable problem
By robbertds1 in forum AWT / SwingReplies: 1Last Post: 05-20-2008, 06:34 PM -
Jtable duplicates through Hashtable (JTable condition problem) my assignment plz help
By salmanpirzada1 in forum Advanced JavaReplies: 2Last Post: 05-15-2008, 10:15 AM -
Problem with JTable
By Felissa in forum AWT / SwingReplies: 2Last Post: 07-04-2007, 09:25 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks