Understanding mnemonic [message #1148493] |
Mon, 21 October 2013 10:50  |
Eclipse User |
|
|
|
Hi,
I have a label and a textfield, the label's text has a mnemonic (&label).
My question is, how does SWT determine to which field the label belongs?
In my case, when I press "alt+l", the textfield gets focus. But I haven't specified that the label belongs to the textfield. In Swing there is a method: label.setLabelFor(textfield);
In my special case, the label and textfield are not directly next to each other, which means that when I press "alt+l", the textfield does not get the focus. Is there a way to intercept the mnemonic and implement some custom logic?
Thank you very much in advance
|
|
|
Re: Understanding mnemonic [message #1170317 is a reply to message #1148493] |
Mon, 04 November 2013 10:05  |
Eclipse User |
|
|
|
Okay, I have solved it by adding a new traverse listener:
addTraverseListener(new TraverseListener() {
@Override
public void keyTraversed(TraverseEvent e) {
setFocusOnMnemonic(e);
}
});
protected void setFocusOnMnemonic(TraverseEvent e) {
if (e.detail == SWT.TRAVERSE_MNEMONIC) {
char pressedMnemonic = e.character;
if (Character.toLowerCase(StringUtility.getMnemonic(getText())) != pressedMnemonic) {
return;
}
if (m_labelFor != null) {
if (m_labelFor.setFocus()) {
e.doit = true;
e.detail = SWT.TRAVERSE_NONE;
}
}
}
}
m_labelFor represents the Control which shall get the focus
|
|
|
Powered by
FUDForum. Page generated in 0.04506 seconds