[MAC] Locking focus on a Text Widget [message #443980] |
Tue, 05 October 2004 10:08 |
Eclipse User |
|
|
|
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 |
Patrice Drolet 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 |
Eclipse User |
|
|
|
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!
|
|
|
Powered by
FUDForum. Page generated in 0.02896 seconds