Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » [MAC] Locking focus on a Text Widget
[MAC] Locking focus on a Text Widget [message #443980] Tue, 05 October 2004 10:08 Go to next message
Eclipse UserFriend
Originally posted by: ndee.mac.com

Hi,

im trying to lock the Focus on a Text Widget if the User enters an
invalid Value. I did the following:

public class Main {

public static void main(String[] args) {
Display display = new Display();
Shell shell = new Shell(display);
shell.setLayout(new FillLayout(SWT.VERTICAL));
final Text text1 = new Text(shell, SWT.NONE);
text1.addFocusListener(new FocusListener() {
public void focusGained(FocusEvent e) {
}
public void focusLost(FocusEvent e) {
if (!text1.getText().equals(new String("Hello"))) {
((Text) e.widget).setFocus();
}
}
});
final Text text2 = new Text(shell, SWT.NONE);
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
}

This works just fine on Windows but doesn't work on Mac OS X, is this a
Bug or some Kind of Carbon-Related Issue?

Thanks
Andi
Re: [MAC] Locking focus on a Text Widget [message #444056 is a reply to message #443980] Wed, 06 October 2004 04:55 Go to previous messageGo to next message
Patrice Drolet is currently offline Patrice DroletFriend
Messages: 2
Registered: July 2009
Junior Member
Hi,

The problem is that the focus has been lost for the benefit of another
control and the Macos does not seem to like...

The way I manage this is with a timer.

package ca.infodata.util;

import org.eclipse.swt.widgets.Control;

/**
* Pour mettre le focus au control c dans i msec.
* @author pdrolet
*/
public class SetFocusTimer {

/**
* Pour mettre le focus au Control c dans i msec.
* @param c le control qui aura le focus
* @param i le nombre de milli-secondes
*/
public SetFocusTimer(Control c, int i) {
final Control control = c;
final int timeToWait = i;
c.getDisplay().timerExec(timeToWait, new Runnable() {
public void run() {
control.setFocus();
}
});
}
}

Then in the focusout of a control I want it to regain the focus, I call
this method with the control and lenght of time (msec) for the timer to
fire:

new SetFocusTimer(myText, 20);




Stotzer Andreas wrote:
> Hi,
>
> im trying to lock the Focus on a Text Widget if the User enters an
> invalid Value. I did the following:
>
> public class Main {
>
> public static void main(String[] args) {
> Display display = new Display();
> Shell shell = new Shell(display);
> shell.setLayout(new FillLayout(SWT.VERTICAL));
> final Text text1 = new Text(shell, SWT.NONE);
> text1.addFocusListener(new FocusListener() {
> public void focusGained(FocusEvent e) {
> }
> public void focusLost(FocusEvent e) {
> if
> (!text1.getText().equals(new
> String("Hello"))) {
> ((Text) e.widget).setFocus();
> }
> }
> });
> final Text text2 = new Text(shell, SWT.NONE);
> shell.open();
> while (!shell.isDisposed()) {
> if (!display.readAndDispatch())
> display.sleep();
> }
> display.dispose();
> }
> }
>
> This works just fine on Windows but doesn't work on Mac OS X, is this a
> Bug or some Kind of Carbon-Related Issue?
>
> Thanks
> Andi
Re: [MAC] Locking focus on a Text Widget [message #444072 is a reply to message #444056] Wed, 06 October 2004 15:40 Go to previous message
Eclipse UserFriend
Originally posted by: ndee.mac.com

Patrice Drolet wrote:
> Hi,
>
> The problem is that the focus has been lost for the benefit of another
> control and the Macos does not seem to like...
>
> The way I manage this is with a timer.
>
> package ca.infodata.util;
>
> import org.eclipse.swt.widgets.Control;
>
> /**
> * Pour mettre le focus au control c dans i msec.
> * @author pdrolet
> */
> public class SetFocusTimer {
>
> /**
> * Pour mettre le focus au Control c dans i msec.
> * @param c le control qui aura le focus
> * @param i le nombre de milli-secondes
> */
> public SetFocusTimer(Control c, int i) {
> final Control control = c;
> final int timeToWait = i;
> c.getDisplay().timerExec(timeToWait, new Runnable() {
> public void run() {
> control.setFocus();
> }
> });
> }
> }
>
> Then in the focusout of a control I want it to regain the focus, I call
> this method with the control and lenght of time (msec) for the timer to
> fire:
>
> new SetFocusTimer(myText, 20);
>
>
>
>
> Stotzer Andreas wrote:
>
>> Hi,
>>
>> im trying to lock the Focus on a Text Widget if the User enters an
>> invalid Value. I did the following:
>>
>> public class Main {
>>
>> public static void main(String[] args) {
>> Display display = new Display();
>> Shell shell = new Shell(display);
>> shell.setLayout(new FillLayout(SWT.VERTICAL));
>> final Text text1 = new Text(shell, SWT.NONE);
>> text1.addFocusListener(new FocusListener() {
>> public void focusGained(FocusEvent e) {
>> }
>> public void focusLost(FocusEvent e) {
>> if
>> (!text1.getText().equals(new
>> String("Hello"))) {
>> ((Text) e.widget).setFocus();
>> }
>> }
>> });
>> final Text text2 = new Text(shell, SWT.NONE);
>> shell.open();
>> while (!shell.isDisposed()) {
>> if (!display.readAndDispatch())
>> display.sleep();
>> }
>> display.dispose();
>> }
>> }
>>
>> This works just fine on Windows but doesn't work on Mac OS X, is this
>> a Bug or some Kind of Carbon-Related Issue?
>>
>> Thanks
>> Andi
>
>
>
That works fine, thanks!
Previous Topic:Dynamicly Adding and Removing CoolItems
Next Topic:xmlhttp
Goto Forum:
  


Current Time: Tue Oct 20 07:28:59 GMT 2020

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

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

Back to the top