Hi,
I have a standard table with all elements enabled for editing. When
I finish editing and press "enter" key the focus moves down.
How can I change this behavior to move right instead?
Thanks.
|
|
0
|
|
|
|
Reply
|
Mike314
|
6/23/2009 7:54:37 AM |
|
Mike314 wrote:
> Hi,
>
> I have a standard table with all elements enabled for editing. When
> I finish editing and press "enter" key the focus moves down.
> How can I change this behavior to move right instead?
Can't see this behaviour:
import java.awt.event.*;
import javax.swing.*;
public class Test {
private void createAndShowGUI() {
JTable table = new JTable(new String[][]{
{"1,1", "1,2"},
{"2,1", "2,2"}}, new String[]{"A", "B"});
JFrame frame = new JFrame("Test");
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame.add(new JScrollPane(table));
frame.pack();
frame.setVisible(true);
}
public static final void main(String args[]) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
new Test().createAndShowGUI();
}
});
}
}
Bye
Michael
|
|
0
|
|
|
|
Reply
|
Michael
|
6/23/2009 8:37:05 AM
|
|
On Jun 23, 6:37=A0pm, Michael Rauscher <michlm...@gmx.de> wrote:
> Mike314 wrote:
> > Hi,
>
> > =A0 =A0I have a standard table with all elements enabled for editing. W=
hen
> > I finish editing and press "enter" key the focus moves down.
> > =A0 =A0How can I change this behavior to move right instead?
>
> Can't see this behaviour:
>
> import java.awt.event.*;
> import javax.swing.*;
>
> public class Test {
> =A0 =A0 =A0private void createAndShowGUI() {
> =A0 =A0 =A0 =A0 =A0JTable table =3D new JTable(new String[][]{
> =A0 =A0 =A0 =A0 =A0 =A0 =A0{"1,1", "1,2"},
> =A0 =A0 =A0 =A0 =A0 =A0 =A0{"2,1", "2,2"}}, new String[]{"A", "B"});
> =A0 =A0 =A0 =A0 =A0JFrame frame =3D new JFrame("Test");
> =A0 =A0 =A0 =A0 =A0frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE=
);
> =A0 =A0 =A0 =A0 =A0frame.add(new JScrollPane(table));
> =A0 =A0 =A0 =A0 =A0frame.pack();
> =A0 =A0 =A0 =A0 =A0frame.setVisible(true);
> =A0 =A0 =A0}
>
> =A0 =A0 =A0public static final void main(String args[]) {
> =A0 =A0 =A0 =A0 =A0SwingUtilities.invokeLater(new Runnable() {
> =A0 =A0 =A0 =A0 =A0 =A0 =A0public void run() {
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0new Test().createAndShowGUI();
> =A0 =A0 =A0 =A0 =A0 =A0 =A0}
> =A0 =A0 =A0 =A0 =A0});
> =A0 =A0 =A0}
>
> }
>
> Bye
> Michael
1. Run
2. Choose first cell (1,1)
3. press some keys (like 123) to change the cell's value. (or even do
nothing - same result)
4. press enter
5. The focus changes to lower cell (2,1).
I need it to change to (1,2) instead.
|
|
0
|
|
|
|
Reply
|
Mike314
|
6/23/2009 8:57:51 AM
|
|
>
> I need it to change to (1,2) instead.
You could dig in ActionMap of the table. The action associated whith the
enter key must be in one of the 3 maps (depending of the focus).
|
|
0
|
|
|
|
Reply
|
Albert
|
6/23/2009 9:02:34 AM
|
|
Mike314 wrote:
> On Jun 23, 6:37 pm, Michael Rauscher <michlm...@gmx.de> wrote:
>> Mike314 wrote:
>>> Hi,
>>> I have a standard table with all elements enabled for editing. When
>>> I finish editing and press "enter" key the focus moves down.
>>> How can I change this behavior to move right instead?
>> Can't see this behaviour:
>>
> 1. Run
> 2. Choose first cell (1,1)
> 3. press some keys (like 123) to change the cell's value. (or even do
> nothing - same result)
> 4. press enter
> 5. The focus changes to lower cell (2,1).
OK, happens if one doesn't double-click or press F2 to start editing.
>
> I need it to change to (1,2) instead.
table.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).
put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0),
"selectNextColumnCell");
Bye
Michael
|
|
0
|
|
|
|
Reply
|
Michael
|
6/23/2009 9:55:05 AM
|
|
In article
<b5dfa6e0-26a7-40a4-b464-aa460645d720@12g2000pri.googlegroups.com>,
Mike314 <michaelst@gmail.com> wrote:
> I have a standard table with all elements enabled for editing. When I
> finish editing and press "enter" key the focus moves down. How can I
> change this behavior to move right instead?
Use a key binding, for example:
JTable table = new JTable(...);
KeyStroke enter = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0);
InputMap map = table.getInputMap(JTable.WHEN_FOCUSED);
map.put(enter, "selectNextColumnCell");
The condition, WHEN_FOCUSED, is one of several defined in JComponent,
and the actionMapKey, "selectNextColumnCell", is one known to
BasicTableUI:
<http://java.sun.com/docs/books/tutorial/uiswing/misc/keybinding.html>
--
John B. Matthews
trashgod at gmail dot com
<http://sites.google.com/site/drjohnbmatthews>
|
|
0
|
|
|
|
Reply
|
John
|
6/23/2009 10:17:35 AM
|
|
On Jun 23, 7:55=A0pm, Michael Rauscher <michlm...@gmx.de> wrote:
> Mike314 wrote:
> > On Jun 23, 6:37 pm, Michael Rauscher <michlm...@gmx.de> wrote:
> >> Mike314 wrote:
> >>> Hi,
> >>> =A0 =A0I have a standard table with all elements enabled for editing.=
When
> >>> I finish editing and press "enter" key the focus moves down.
> >>> =A0 =A0How can I change this behavior to move right instead?
> >> Can't see this behaviour:
>
> > 1. Run
> > 2. Choose first cell (1,1)
> > 3. press some keys (like 123) to change the cell's value. (or even do
> > nothing - same result)
> > 4. press enter
> > 5. The focus changes to lower cell (2,1).
>
> OK, happens if one doesn't double-click or press F2 to start editing.
>
>
>
> > I need it to change to (1,2) instead.
>
> =A0 =A0 =A0 =A0 =A0table.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_=
COMPONENT).
> =A0 =A0 =A0 =A0 =A0put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0),
> =A0 =A0 =A0 =A0 =A0 =A0 =A0"selectNextColumnCell");
>
> Bye
> Michael
Thank you very much. It is what I was looking for.
|
|
0
|
|
|
|
Reply
|
Mike314
|
6/24/2009 7:08:49 AM
|
|
|
6 Replies
975 Views
(page loaded in 0.146 seconds)
Similiar Articles: JTable and Enter key - comp.lang.java.guiHi, I have a standard table with all elements enabled for editing. When I finish editing and press "enter" key the focus moves down. How can I ... Limiting the number of characters in a JTable cell. - comp.lang ...Hi, I have a JTable wherein each cell can have only a fixed number of characters ... of a cell is reached.The user can also navigate to the next cell using the Enter key. JTable how to fill with data - comp.lang.java.guiJTable how to fill with data - comp.lang.java.gui to Form Connection/User Code ... ... JTable and Enter key - comp.lang.java.gui How to set a password in gui form ... Set size of JTable inside a JScrollPane - comp.lang.java ...JTable and Enter key - comp.lang.java.gui You can enter any number of COLUMN commands ... ... I need change ... Set size of JTable inside a JScrollPane ... ... the length ... Event handler problem in JTable - comp.lang.java.guiIs it possible to know what caused a focus lost event? ... If you show a dialog in such a handler, and you click on ... JTable and Enter key - comp.lang.java.gui What ... Disable a JTable row - comp.lang.java.guiI don't need to disable selecting the component for a ... The text is still scrolled to the the inserted row. ... JTable and Enter key - comp.lang.java.gui... getInputMap ... JTable row selection (left and right mouse) - comp.lang.java.gui ...Arrow Key Codes... - comp.lang.asm.x86... up 4BE0 pad left 50E0 pad down 4DE0 pad right ... JTable and Enter key - comp.lang.java.gui I think there must be a way to do ... JTable and input methods (or, and: focus in JTextField) - comp ...JTable and Enter key - comp.lang.java.gui How to capture input of JTextField - comp.lang.java.gui JTable and input methods (or, and: focus in JTextField) - comp ... JTable, edit a cell, but changed value not seen - comp.lang.java ...JTable and Enter key - comp.lang.java.gui... cell (1,1) 3. press some keys (like 123) to change the cell's value. ... for update table with primary key ... in JTable not ... ... Limiting number of characters in a JTable columns? - comp.lang ...JTable and Enter key - comp.lang.java.gui... and character check in JTextField - comp.lang.java ..... developing a java program that allows the user to enter ... JTable and Enter key - Java forums. Thousands of discussion ...Hi, I have a standard table with all elements enabled for editing. When I finish editing and press "enter" key the focus moves down. How can I change this behavior to ... jtable enter key - Java Forum - Tutorials, Articles, Forum ...how can i remove the default jtable enter key action, since i dont want to move the the curser to next row , i have control the enter key 7/20/2012 5:58:58 AM
|