Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.gui > #326

Re: art of writing a resp

From "Fred Kleinschmidt" <fred.kleinschmidt@THRWHITE.remove-dii-this>
Subject Re: art of writing a resp
Message-ID <J9rIsB.8uw@news.boeing.com> (permalink)
Newsgroups comp.lang.java.gui
References <4570a559$0$8743$ed2619ec@ptn-nntp-reader02.plus.net>
Date 2011-04-27 15:26 +0000
Organization TDS.net

Show all headers | View raw


  To: comp.lang.java.programmer

"Wesley Hall" <noreply@example.com> wrote in message 
news:4570a559$0$8743$ed2619ec@ptn-nntp-reader02.plus.net...
> Timasmith wrote:
>> Having played around with someones variant of Swingworker I have found
>> pleasing results with using a background thread for actions initiated
>> by a table, tree or menu.  Clicking on the said item kicks off the
>> action while letting the gui items respond appropriately.  In fact
>> rather than hardcoding it everywhere I extended an ActionListener to do
>> just that.
>
> Just remember that Swing is NOT thread safe so any updates you do to
> visual components should be done on the AWT thread. It is OK to use a
> thread to go off and fetch data etc, but when the data returns and you
> want to display it you must use SwingUtilities.invokeLater to update the
> GUI as you will get occasional strange behaviour.
>
>> Now when it comes to buttons there is a different story.  When you
>> press a button you want a good solid push but with the background
>> thread I get a bouncy button that immediately springs back to its
>> position - too quickly in my estimation.  Since the action it is
>> performing may be quick or slow its difficult to guage the slow ones
>> only for background processing.
>>
>> I guess I could introduce an artifical pause for the button but any
>> other ideas on that.
>
> Not really, it has been a while since I did any swing but presumably the
> button stays 'pressed' for as long as the action listener is running. If
> you are making that run very short with threading, it is not suprising
> that this is happening.

Not necessarily. Usually, when the user presses down on the mouse
button, the PushButton gets a ButtonDown event, and draws itself as
"pushed" (or "Armed").
When the user releases the button (without leaving the PushButton),
the PushButton gets re-drawn as unpushed (unarmed), and it is only
now that the action event is delivered.  Note that the order of these
last two things may be dependent on LAF and/or platform.

On the other hand, if the user uses the keyboard mnemonic or shortcut
to press the Button, the action takes place on the KeyPress event
rather than on the KeyRelease event, since many platforms do not
have the concept of KeyRelease.
-- 
Fred L. Kleinschmidt
Boeing Associate Technical Fellow
Technical Architect, Software Reuse Project


> <snip>

---
 * Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet!
--- Synchronet 3.15a-Win32 NewsLink 1.92
Time Warp of the Future BBS - telnet://time.synchro.net:24

Back to comp.lang.java.gui | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

art of writing a responsi "Timasmith" <timasmith@THRWHITE.remove-dii-this> - 2011-04-27 15:26 +0000
  Re: art of writing a resp "Wesley Hall" <wesley.hall@THRWHITE.remove-dii-this> - 2011-04-27 15:26 +0000
    Re: art of writing a resp "Timasmith" <timasmith@THRWHITE.remove-dii-this> - 2011-04-27 15:26 +0000
    Re: art of writing a resp "Fred Kleinschmidt" <fred.kleinschmidt@THRWHITE.remove-dii-this> - 2011-04-27 15:26 +0000
  Re: art of writing a resp "Andrew Thompson" <andrew.thompson@THRWHITE.remove-dii-this> - 2011-04-27 15:26 +0000
    Re: art of writing a resp "Lew" <lew@THRWHITE.remove-dii-this> - 2011-04-27 15:26 +0000

csiph-web