Reputation: 213
I have a Java SWT desktop application with various pages etc. pp. It works perfectly well, except the tab order - not at all. When I am in "field 1" and press Tab on my keyboard, I want the application to jump to "field 2", so I don't have to click to the second field after I entered the information in the first one.
Generally there is the "setTabList", where you can set the right order for "tabbing through the form". My problem is I don't even need to set the order right, tabbing doesn't work at all.
When I am in a field of my form and press Tab, for a millisecond I can see the Windows "working circle" (or whatever it is called) and nothing happens. The cursor stays exactly at the same position. It won't jump to another field and I have no idea why.
Generally my code:
public void createControl(Composite parent) {
Composite container = new Composite(parent, SWT.BORDER);
setControl(container);
fieldOne = new StyledText(container, SWT.NONE);
fieldOne.setBounds(whatever);
fieldOne.addKeyListener(new KeyAdapter() {
public void keyReleased(KeyEvent arg0) {
txtChanged();
}
});
fieldTwo = new StyledText(container, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
fieldOne.setBounds(whatever);
fieldOne.addKeyListener(new KeyAdapter() {
public void keyReleased(KeyEvent arg0) {
txtChanged();
}
});
Control[] controls = { fieldOne, fieldTwo };
container.setTabList(controls);
}
Even if I leave the Control[] and container.setTabList rows out, nothing happens.
Any ideas?
Upvotes: 1
Views: 1050
Reputation: 111217
In a StyledText
control Tab normally just moves the cursor to the next tab stop inside the control. Ctrl+Tab moves to the next control.
You can override this with a traverse listener:
fieldOne.addTraverseListener(new TraverseListener() {
@Override
public void keyTraversed(final TraverseEvent e) {
if (e.detail == SWT.TRAVERSE_TAB_NEXT || e.detail == SWT.TRAVERSE_TAB_PREVIOUS) {
e.doit = true;
}
}
});
It is also possible that your key listener is interfering with normal operation. Use a ModifyListener
if all you want to know is that the text has changed.
Upvotes: 2