Home » Eclipse Projects » Standard Widget Toolkit (SWT) » SWT.PASSWORD and enter key on Mac(Want to have a listener on my Text box that has the SWT.PASSWORD)
|
Re: SWT.PASSWORD and enter key on Mac [message #508388 is a reply to message #508058] |
Mon, 18 January 2010 15:51 |
Grant Gayed Messages: 2150 Registered: July 2009 |
Senior Member |
|
|
Hi,
You're seeing a bug in swt 3.5.x that is fixed in the 3.6 stream, so if
you're willing/able to move up to a 3.6 stable release then this should work
for you. Another option would be to use swt's 3.5.x carbon port since it
does not have this problem (though we're generally encouraging apps to adopt
the cocoa port as much as possible).
If neither of these options appeal then you could work around this problem
by changing your dialog's implementation to something like the snippet
below, which is functionally equivalent, but just a bit awkward.
public static void main(String[] args) {
final Display display = new Display();
Shell shell = new Shell(display);
shell.setBounds(10,10,200,200);
shell.setLayout(new GridLayout(2, false));
new Label(shell, SWT.NONE).setText("Name:");
final Text nameText = new Text(shell, SWT.SINGLE);
nameText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
nameText.addTraverseListener(new TraverseListener() {
public void keyTraversed(TraverseEvent e) {
if (e.detail == SWT.TRAVERSE_RETURN) {
e.doit = false; // don't invoke the default button
nameText.traverse(SWT.TRAVERSE_TAB_NEXT);
}
}
});
new Label(shell, SWT.NONE).setText("Password:");
new Text(shell, SWT.PASSWORD).setLayoutData(new
GridData(GridData.FILL_HORIZONTAL));
Button login = new Button(shell, SWT.PUSH);
login.setText("Login");
shell.setDefaultButton(login);
login.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
System.out.println("login!");
}
});
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) display.sleep();
}
display.dispose();
}
Grant
"dwain" <dwain.bethel@vanns.net> wrote in message
news:hiq8hc$rpf$1@build.eclipse.org...
> I am building an RCP application that must run on multiple platforms. I
have a login screen that shows up when you first load the application with a
textbox for your username and one for your password. I have a keylistener
on both text boxes that listens for the enter key. If you hit the enter key
while in the username box, it just goes to the password box, if you hit the
enter key in the password box, it calls the login function. This works
perfectly in Windows and Linux. However on a Mac it does not work. It
seems that you can't have a key listener on an Text widget with the
SWT.PASSWORD style in Mac.
>
> I also tried a selection listener, since the enter key often calls the
defaultWidgetSelected(Event e) method of the selection listener. That also
works perfectly in Windows but not at all in Mac. I really would like a way
to hit the enter key after you type in your password and have that call my
login method, any ideas?
>
> Thank you.
|
|
|
Re: SWT.PASSWORD and enter key on Mac [message #508389 is a reply to message #508388] |
Mon, 18 January 2010 15:55 |
Grant Gayed Messages: 2150 Registered: July 2009 |
Senior Member |
|
|
In the last reply, "3.6 stable release" should have been "3.6 milestone
release". The first 3.6.x stable release will be in June 2010.
Grant
"Grant Gayed" <grant_gayed@ca.ibm.com> wrote in message
news:hj2018$sqp$1@build.eclipse.org...
> Hi,
>
> You're seeing a bug in swt 3.5.x that is fixed in the 3.6 stream, so if
> you're willing/able to move up to a 3.6 stable release then this should
work
> for you. Another option would be to use swt's 3.5.x carbon port since it
> does not have this problem (though we're generally encouraging apps to
adopt
> the cocoa port as much as possible).
>
> If neither of these options appeal then you could work around this problem
> by changing your dialog's implementation to something like the snippet
> below, which is functionally equivalent, but just a bit awkward.
>
> public static void main(String[] args) {
> final Display display = new Display();
> Shell shell = new Shell(display);
> shell.setBounds(10,10,200,200);
> shell.setLayout(new GridLayout(2, false));
> new Label(shell, SWT.NONE).setText("Name:");
> final Text nameText = new Text(shell, SWT.SINGLE);
> nameText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
> nameText.addTraverseListener(new TraverseListener() {
> public void keyTraversed(TraverseEvent e) {
> if (e.detail == SWT.TRAVERSE_RETURN) {
> e.doit = false; // don't invoke the default button
> nameText.traverse(SWT.TRAVERSE_TAB_NEXT);
> }
> }
> });
> new Label(shell, SWT.NONE).setText("Password:");
> new Text(shell, SWT.PASSWORD).setLayoutData(new
> GridData(GridData.FILL_HORIZONTAL));
> Button login = new Button(shell, SWT.PUSH);
> login.setText("Login");
> shell.setDefaultButton(login);
> login.addSelectionListener(new SelectionAdapter() {
> public void widgetSelected(SelectionEvent e) {
> System.out.println("login!");
> }
> });
> shell.open();
> while (!shell.isDisposed()) {
> if (!display.readAndDispatch()) display.sleep();
> }
> display.dispose();
> }
>
> Grant
>
>
> "dwain" <dwain.bethel@vanns.net> wrote in message
> news:hiq8hc$rpf$1@build.eclipse.org...
> > I am building an RCP application that must run on multiple platforms. I
> have a login screen that shows up when you first load the application with
a
> textbox for your username and one for your password. I have a keylistener
> on both text boxes that listens for the enter key. If you hit the enter
key
> while in the username box, it just goes to the password box, if you hit
the
> enter key in the password box, it calls the login function. This works
> perfectly in Windows and Linux. However on a Mac it does not work. It
> seems that you can't have a key listener on an Text widget with the
> SWT.PASSWORD style in Mac.
> >
> > I also tried a selection listener, since the enter key often calls the
> defaultWidgetSelected(Event e) method of the selection listener. That
also
> works perfectly in Windows but not at all in Mac. I really would like a
way
> to hit the enter key after you type in your password and have that call my
> login method, any ideas?
> >
> > Thank you.
>
>
|
|
| | |
Goto Forum:
Current Time: Mon Dec 09 11:23:12 GMT 2024
Powered by FUDForum. Page generated in 0.03419 seconds
|