Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / February 2010

Tip: Looking for answers? Try searching our database.

SWT: TextField ModifyListener

Thread view: 
claus.kick@googlemail.com - 07 Feb 2010 11:25 GMT
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.
John B. Matthews - 07 Feb 2010 18:04 GMT
In article
<e6f9d021-5fda-4727-99ce-57edda70bafd@k41g2000yqm.googlegroups.com>,

> 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:
[...]
> The following is happening:
>
[quoted text clipped - 8 lines]
> and catch the keyup event, but I am interested as to how this is done
> the right way.

I don't use SWT much, but I wonder if a VerifyListener would be a good
alternative.

<http://www.java2s.com/Tutorial/Java/0280__SWT/Events.htm>
<http://www.java2s.com/Tutorial/Java/0280__SWT/UsingVerifyListener.htm>

Signature

John B. Matthews
trashgod at gmail dot com
<http://sites.google.com/site/drjohnbmatthews>

claus.kick@googlemail.com - 09 Feb 2010 17:04 GMT
> In article
> <e6f9d021-5fda-4727-99ce-57edda70b...@k41g2000yqm.googlegroups.com>,
[quoted text clipped - 18 lines]
> I don't use SWT much, but I wonder if a VerifyListener would be a good
> alternative.

Hello John,

good idea, I will do just that! However, an answer to the original
question would be nice, as well ;)
John B. Matthews - 10 Feb 2010 00:11 GMT
In article
<5e9f99ee-e1b8-4465-87f3-cdd638c2d9a7@x22g2000yqx.googlegroups.com>,

> > I don't use SWT much, but I wonder if a VerifyListener would be a
> > good alternative.
> [...]
> good idea, I will do just that! However, an answer to the original
> question would be nice, as well ;)

I don't know either; that's just what I did last time I had a similar
problem. As you can see, I was droping the last key typed, too. What I
really wanted to do was verify the input after typing.

<http://applecommander.cvs.sourceforge.net/viewvc/applecommander/AppleCom
mander/src/com/webcodepro/applecommander/ui/swt/wizard/diskimage/DiskImag
eNamePane.java?view=diff&r1=text&tr1=1.5&r2=text&tr2=1.3&diff_format=h>

Signature

John B. Matthews
trashgod at gmail dot com
<http://sites.google.com/site/drjohnbmatthews>

claus.kick@googlemail.com - 10 Feb 2010 12:29 GMT
> In article
> <5e9f99ee-e1b8-4465-87f3-cdd638c2d...@x22g2000yqx.googlegroups.com>,
[quoted text clipped - 9 lines]
> problem. As you can see, I was droping the last key typed, too. What I
> really wanted to do was verify the input after typing.

Well, I am not loosing the last key, but the first key and I am not
sure why - perhaps the control looses focus?
Perhaps the framework sets focus to the control changing its
background color instead of staying where the event is being
triggered?

And where is the SWT community hiding? :)
John B. Matthews - 10 Feb 2010 14:06 GMT
In article
<78cb03db-7656-420e-878c-0f325d4f3911@a32g2000yqm.googlegroups.com>,

> And where is the SWT community hiding? :)

The first rule of SWT is not to talk about SWT, so I'm encrypting these
links with rot-13, twice.

<http://stackoverflow.com/questions/tagged/swt>
<http://www.eclipsezone.com/eclipse/forums/f18120.html>
<http://www.java-tips.org/other-api-tips/eclipse/how-to-validate-swt-text
-controls.html>

Signature

John B. Matthews
trashgod at gmail dot com
<http://sites.google.com/site/drjohnbmatthews>

Lew - 10 Feb 2010 17:23 GMT
claus.kick@googlemail.com wrote:
>> And where is the SWT community hiding? :)

> The first rule of SWT is not to talk about SWT,

'cuz they're embarrassed?

> so I'm encrypting these links with rot-13, twice.

That was unbelievably clever.

> <http://stackoverflow.com/questions/tagged/swt>
> <http://www.eclipsezone.com/eclipse/forums/f18120.html>
> <http://www.java-tips.org/other-api-tips/eclipse/how-to-validate-swt-text-control
s.html
>

And just to start a flame war (perhaps we should shift to a new thread for
this?), what are the advantages and disadvantages of SWT wrt Swing?

I confess I've never even looked at an SWT tutorial or Javadocs, much less
used it.

Signature

Lew

John B. Matthews - 11 Feb 2010 02:48 GMT
> And just to start a flame war (perhaps we should shift to a new
> thread for this?), what are the advantages and disadvantages of SWT
> wrt Swing?
>
> I confess I've never even looked at an SWT tutorial or Javadocs, much
> less used it.

This is an interesting question that deserves a more thorough answer,
but I have a few observations.

I've used two of the premier exemplars of each technology, NetsBeans &
Eclipse, for several years. As they have evolved, I can't help but think
that each is better for having competed against the other.

When I came to the project cited above, ca. 2003, it was to add command
line functionality. I knew almost nothing about either SWT or Swing.
Since then I've patched a few SWT bugs, but it seemed laborious. In
contrast, I enjoy using Swing, and I've learned a lot from it's design.

Two factors seem to have made a critical difference: First, Swing enjoys
a comprehensive and frequently updated tutorial. Second, numerous
participants in clj have generously answered my questions and amplified
on my own tyro responses.

Signature

John B. Matthews
trashgod at gmail dot com
<http://sites.google.com/site/drjohnbmatthews>

RedGrittyBrick - 12 Feb 2010 12:05 GMT
> And just to start a flame war (perhaps we should shift to a new thread
> for this?), what are the advantages and disadvantages of SWT wrt Swing?
>
> I confess I've never even looked at an SWT tutorial or Javadocs, much
> less used it.

Way back before I started using Swing, I did briefly consider SWT. The
main advantage of SWT seemed to be that the L&F was much more like the
platform native L&F. Initially this was very attractive as the default
Swing L&F stuck out like a sore thumb. Pluggable L&Fs seems to have
largely eliminated this advantage for SWT, at least for mundane apps.

The main downside of SWT seemed to me to be portability to other
platforms. It also gradually became apparent to me that there was a much
more active community for Swing than for SWT.

Since I haven't actually used SWT, my reasons for staying with Swing are
mainly community support, inertia and a lack of knowledge of any
significant benefits to changing to SWT.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2010 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.