Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Understanding mnemonic
Understanding mnemonic [message #1148493] Mon, 21 October 2013 14:50 Go to next message
Matthias Nick is currently offline Matthias NickFriend
Messages: 197
Registered: August 2013
Senior Member
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 15:05 Go to previous message
Matthias Nick is currently offline Matthias NickFriend
Messages: 197
Registered: August 2013
Senior Member
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
Previous Topic:FileDialog does not show
Next Topic:Mnemonic behavior
Goto Forum:
  


Current Time: Fri Apr 19 12:35:32 GMT 2024

Powered by FUDForum. Page generated in 0.01849 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top