Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.gui > #3209 > unrolled thread
| Started by | "RC" <rc@THRWHITE.remove-dii-this> |
|---|---|
| First post | 2011-04-27 15:43 +0000 |
| Last post | 2011-04-27 15:43 +0000 |
| Articles | 5 — 4 participants |
Back to article view | Back to comp.lang.java.gui
Popup similar to Tooltip "RC" <rc@THRWHITE.remove-dii-this> - 2011-04-27 15:43 +0000
Re: Popup similar to Tool "Eric Sosman" <eric.sosman@THRWHITE.remove-dii-this> - 2011-04-27 15:43 +0000
Re: Popup similar to Tool "Daniel Pitts" <daniel.pitts@THRWHITE.remove-dii-this> - 2011-04-27 15:43 +0000
Re: Popup similar to Tool "RC" <rc@THRWHITE.remove-dii-this> - 2011-04-27 15:43 +0000
Re: Popup similar to Tool "Roedy Green" <roedy.green@THRWHITE.remove-dii-this> - 2011-04-27 15:43 +0000
| From | "RC" <rc@THRWHITE.remove-dii-this> |
|---|---|
| Date | 2011-04-27 15:43 +0000 |
| Subject | Popup similar to Tooltip |
| Message-ID | <fpv9n9$6us$1@news.nems.noaa.gov> |
To: comp.lang.java.programmer
I want a simple popup for few seconds
Popup popup = new Popup(null, new JLabel("Done"), 10, 10);
popup.show();
try {
Thread.sleep(2000);
} catch (InterruptedException ie) {
}
popup.hide();
Everything is OK except I don't see the word "Done" in the label.
If I comment out the lines for try, Thread.sleep(###) and catch
Then I can see the word "Done in the label, then I can't make the popup
for few seconds.
Anyone knows why the word "Done" won't show up if I use Thread.sleep?
Any idea how do I fix the problem?
I don't need JProgressBar nor JMonitor for my simple application.
I want similar to the Tooltip popup for few seconds, but without
move the mouse pointer to a particular JComponent.
Thank you in advance!
---
* 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
[toc] | [next] | [standalone]
| From | "Eric Sosman" <eric.sosman@THRWHITE.remove-dii-this> |
|---|---|
| Date | 2011-04-27 15:43 +0000 |
| Subject | Re: Popup similar to Tool |
| Message-ID | <1203975768.656232@news1nwk> |
| In reply to | #3209 |
To: comp.lang.java.programmer
RC wrote:
>
> I want a simple popup for few seconds
>
> Popup popup = new Popup(null, new JLabel("Done"), 10, 10);
> popup.show();
>
> try {
> Thread.sleep(2000);
> } catch (InterruptedException ie) {
> }
> popup.hide();
>
> Everything is OK except I don't see the word "Done" in the label.
> If I comment out the lines for try, Thread.sleep(###) and catch
> Then I can see the word "Done in the label, then I can't make the popup
> for few seconds.
>
> Anyone knows why the word "Done" won't show up if I use Thread.sleep?
You're probably doing the whole thing on the event
dispatching thread, which means the entire GUI stalls
while you're in sleep(). Presumably, it stalls just a
moment or two before the text would have become visible,
and when sleep() returns you tear down the popup before
the text has a chance to finish painting.
> Any idea how do I fix the problem?
Do your sleeping on a separate thread, letting the
EDT run without interruption. In your separate thread,
use SwingUtilities.invokeLater() to do things to the GUI.
--
Eric.Sosman@sun.com
---
* 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
[toc] | [prev] | [next] | [standalone]
| From | "Daniel Pitts" <daniel.pitts@THRWHITE.remove-dii-this> |
|---|---|
| Date | 2011-04-27 15:43 +0000 |
| Subject | Re: Popup similar to Tool |
| Message-ID | <47c34a8e$0$8301$4d87748@newsreader.readnews.com> |
| In reply to | #3210 |
To: comp.lang.java.programmer
Eric Sosman wrote:
> RC wrote:
>>
>> I want a simple popup for few seconds
>>
>> Popup popup = new Popup(null, new JLabel("Done"), 10, 10);
>> popup.show();
>>
>> try {
>> Thread.sleep(2000);
>> } catch (InterruptedException ie) {
>> }
>> popup.hide();
>>
>> Everything is OK except I don't see the word "Done" in the label.
>> If I comment out the lines for try, Thread.sleep(###) and catch
>> Then I can see the word "Done in the label, then I can't make the popup
>> for few seconds.
>>
>> Anyone knows why the word "Done" won't show up if I use Thread.sleep?
>
> You're probably doing the whole thing on the event
> dispatching thread, which means the entire GUI stalls
> while you're in sleep(). Presumably, it stalls just a
> moment or two before the text would have become visible,
> and when sleep() returns you tear down the popup before
> the text has a chance to finish painting.
>
> > Any idea how do I fix the problem?
>
> Do your sleeping on a separate thread, letting the
> EDT run without interruption. In your separate thread,
> use SwingUtilities.invokeLater() to do things to the GUI.
>
Actually, I suggest using a Timer task instead of Thread.sleep in any case.
--
Daniel Pitts' Tech Blog: <http://virtualinfinity.net/wordpress/>
---
* 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
[toc] | [prev] | [next] | [standalone]
| From | "RC" <rc@THRWHITE.remove-dii-this> |
|---|---|
| Date | 2011-04-27 15:43 +0000 |
| Subject | Re: Popup similar to Tool |
| Message-ID | <fq18si$amp$1@news.nems.noaa.gov> |
| In reply to | #3212 |
To: comp.lang.java.programmer Daniel Pitts wrote: > Actually, I suggest using a Timer task instead of Thread.sleep in any case. Two thumbs up! --- * 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
[toc] | [prev] | [next] | [standalone]
| From | "Roedy Green" <roedy.green@THRWHITE.remove-dii-this> |
|---|---|
| Date | 2011-04-27 15:43 +0000 |
| Subject | Re: Popup similar to Tool |
| Message-ID | <oq39s39b51kmof92cogq0tje995h61clir@4ax.com> |
| In reply to | #3209 |
To: comp.lang.java.programmer
On Mon, 25 Feb 2008 15:50:49 -0500, RC <raymond.chui@nospam.noaa.gov>
wrote, quoted or indirectly quoted someone who said :
>try {
> Thread.sleep(2000);
>} catch (InterruptedException ie) {
>}
>popup.hide();
your problem is you made the Swing thread sleep, so it can't do any
painting work, i.e. serving the event queue.
See http://mindprod.com/jgloss/timer.html
http://mindprod.com/jgloss/sleep.html
--
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com
---
* 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
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.java.gui
csiph-web