Hi !
Featured games (91)
games approved by the League of Dukes
Games in Showcase (757)
Games in Android Showcase (229)
games submitted by our members
Games in WIP (844)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Swing Components Blocking  (Read 2011 times)
0 Members and 1 Guest are viewing this topic.
Offline dudley442

Senior Newbie

Java games rock!

« Posted 2004-08-26 19:24:00 »

Hey everyone,

Now I've been programming for nearly two years in Java, but this one little tidbit has got me stumped.

I've got two separate threads running.  One doing painting in a JFrame, and the other performing I/O work.

For some odd reason, when the I/O thread is doing its thing, the components refuse to paint in the JFrame.  Even if I try calling repaint(), it will ignore the call until the I/O has finished.

Any ideas?
Offline swpalmer

JGO Coder

Exp: 12 years

Where's the Kaboom?

« Reply #1 - Posted 2004-08-26 20:45:34 »

Need more info.  What is the I/O thread doing exactly?  Is it interacting with any of the UI stuff at all?

Offline trembovetski

Senior Devvie

If only I knew what I'm talking about!

« Reply #2 - Posted 2004-08-27 01:03:29 »

It'd help if you can post a stack trace when the IO/not painting happens (Ctrl+Break on win, Ctrl+\ on unix).
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline dudley442

Senior Newbie

Java games rock!

« Reply #3 - Posted 2004-08-27 15:36:11 »

There is no interaction with the UI whatsoever.  What the I/O is doing is reading in a list of files and writing their absolute pathnames to a text file.  It is on a completely separate thread from the GUI.

The thread that is running responsible for painting in the JFrame may make a call during the I/O operation like:


And that will work; but, for some reason, the painting functions will not.  The JFrame stays blank until the I/O operation ceases.
Offline kevglass

« JGO Spiffy Duke »

Medals: 319
Projects: 25
Exp: 22 years

Coder, Trainee Pixel Artist, Game Reviewer

« Reply #4 - Posted 2004-08-27 15:40:23 »

Are you calling repaint() with no arguments? If so, that actually just indicates to the AWT thread (running in the background) that the window should be repainted as soon as possible.

If you call repaint(long ms) where ms is the number of milliseconds that are "allowed" to pass before the repaint of the window occurs. Calling repaint(0) should force instant repaint.

However, if your I/O thread is running at full speed (i.e. no sleep() or yield()) then on some system it'll block other threads altogether.


Offline dudley442

Senior Newbie

Java games rock!

« Reply #5 - Posted 2004-08-27 15:52:14 »

Whoops!  Grin

As sure as I was yesterday that the I/O operation was being done on a totally separate thread, it turns out that I was wrong about that.

Thanks for the help, though.  That repaint(0) call will definitely come in handy.

Anyway, I was making a program which writes the absolute pathname of each and every single file and folder inside a given directory to a specified text file.  Works now.
Pages: [1]
  ignore  |  Print  

EgonOlsen (45 views)
2018-06-10 19:43:48

EgonOlsen (27 views)
2018-06-10 19:43:44

EgonOlsen (47 views)
2018-06-10 19:43:20

DesertCoockie (210 views)
2018-05-13 18:23:11

nelsongames (127 views)
2018-04-24 18:15:36

nelsongames (126 views)
2018-04-24 18:14:32

ivj94 (867 views)
2018-03-24 14:47:39

ivj94 (128 views)
2018-03-24 14:46:31

ivj94 (779 views)
2018-03-24 14:43:53

Solater (143 views)
2018-03-17 05:04:08
Java Gaming Resources
by philfrei
2017-12-05 19:38:37

Java Gaming Resources
by philfrei
2017-12-05 19:37:39

Java Gaming Resources
by philfrei
2017-12-05 19:36:10

Java Gaming Resources
by philfrei
2017-12-05 19:33:10

List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05 is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!