[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [platform-swt-dev] SWT: TextField ModifyListener
|
Hi Claus, (note that the correct
place for swt usage questions is the eclipse.platform.swt newsgroup, see
http://www.eclipse.org/forums/)
You'll get the behaviour you want it
you listen for Verify events instead of Modify, like in the snippet below:
public static void main(String[] args)
{
Display display = new
Display();
Shell shell = new Shell(display);
shell.setBounds(10,10,200,200);
shell.setLayout(new GridLayout());
final Text text1 = new
Text(shell, SWT.SINGLE);
final Text text2 = new
Text(shell, SWT.SINGLE);
Listener listener = new
Listener() {
public void
handleEvent(Event event) {
if (event.widget == text1) {
if (text2.getText().length() > 0) {
text2.setText("");
}
} else { /* event.widget == text2 */
if (text1.getText().length() > 0) {
text1.setText("");
}
}
}
};
text1.addListener(SWT.Verify,
listener);
text2.addListener(SWT.Verify,
listener);
shell.open();
while (!shell.isDisposed())
{
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
Grant
Claus Kick <claus.kick@xxxxxxxxxxxxxx>
Sent by: platform-swt-dev-bounces@xxxxxxxxxxx
02/09/10 12:01 PM
Please respond to
"Eclipse Platform SWT component developers list."
<platform-swt-dev@xxxxxxxxxxx> |
|
To
| platform-swt-dev@xxxxxxxxxxx
|
cc
|
|
Subject
| [platform-swt-dev] SWT: TextField ModifyListener |
|
Hello everyone,
quick question:
If I have two text fields and want to clear
the text of one when there
is a ModifyEvent on the other one, I do the following:
public class OrderModifyListener implements
ModifyListener
{
MainWindow mainWindow;
public OrderModifyListener(MainWindow
window)
{
mainWindow = window;
}
public void
modifyText(ModifyEvent e)
{
if (!(mainWindow.getQualifierField().getText().equals("")))
{
mainWindow.getQualifierField().setText("");
}
}
}
The following is happening:
If there is text in the Qualifierfield,
it is being cleared, BUT the
character typed in the textfield listening to the event gets lost. All
further typed characters are being entered properly.
To me, this appears as if the keyup event
which should insert the
character is being lost when the modify event is being caught.
What am I doing wrong? I could of course
just implement a KeyListener
and catch the keyup event, but I am interested as to how this is done
the right way.
Sorry to ask about this on this list, but there appears to be no other
place, at least I was unable to find it._______________________________________________
platform-swt-dev mailing list
platform-swt-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/platform-swt-dev