AppletTalk.com Forum Index AppletTalk.com
Java discussions newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Swing JPanel PaintComponent Issue
Goto page 1, 2  Next
 
Post new topic   Reply to topic    AppletTalk.com Forum Index -> Java GUI Toolkits
View previous topic :: View next topic  
Author Message
matt
Guest





PostPosted: Mon Nov 29, 2004 1:11 am    Post subject: Swing JPanel PaintComponent Issue Reply with quote



I have a JFrame that I have undecorated and in full screen mode. To
draw on the screen, I add a JPanel and draw on that and go for a
setVisible(true). Then, I do what I need and do a setVisible(false)
and go forward.

Sometimes, though, my application will just hang and not paint
anything - at various `screens' ... I'm not doing any threading stuff
in my code, so I don't think that's it. Any ideas?

Thanks

[ummaycoc@localhost java]$ javac -version
javac 1.5.0
javac: no source files
Usage: javac <options> <source files>
where possible options include:
-g Generate all debugging info
-g:none Generate no debugging info
-g:{lines,vars,source} Generate only some debugging info
-nowarn Generate no warnings
-verbose Output messages about what the compiler
is doing
-deprecation Output source locations where deprecated
APIs are used
-classpath <path> Specify where to find user class files
-cp <path> Specify where to find user class files
-sourcepath <path> Specify where to find input source files
-bootclasspath <path> Override location of bootstrap class
files
-extdirs <dirs> Override location of installed extensions
-endorseddirs <dirs> Override location of endorsed standards
path
-d <directory> Specify where to place generated class
files
-encoding <encoding> Specify character encoding used by source
files
-source <release> Provide source compatibility with
specified release
-target <release> Generate class files for specific VM
version
-version Version information
-help Print a synopsis of standard options
-X Print a synopsis of nonstandard options
-J<flag> Pass <flag> directly to the runtime
system

[ummaycoc@localhost java]$ java -version
java version "1.5.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-b64)
Java HotSpot(TM) Client VM (build 1.5.0-b64, mixed mode, sharing)

[ummaycoc@localhost java]$ uname -a
Linux localhost 2.6.3-7mdk-i686-up-4GB #1 Wed Mar 17 15:17:23 CET 2004
i686 unknown unknown GNU/Linux
Back to top
John McGrath
Guest





PostPosted: Mon Nov 29, 2004 4:34 am    Post subject: Re: Swing JPanel PaintComponent Issue Reply with quote



On 11/28/2004 at 8:11:49 PM, matt wrote:

Quote:
Sometimes, though, my application will just hang and not paint
anything - at various `screens' ... I'm not doing any threading stuff
in my code, so I don't think that's it. Any ideas?

No code, no ideas.

--
Regards,

John McGrath

Back to top
matt
Guest





PostPosted: Mon Nov 29, 2004 11:11 pm    Post subject: Re: Swing JPanel PaintComponent Issue Reply with quote



"John McGrath" <ng (AT) jpmcgrath (DOT) net> wrote

Quote:
On 11/28/2004 at 8:11:49 PM, matt wrote:

Sometimes, though, my application will just hang and not paint
anything - at various `screens' ... I'm not doing any threading stuff
in my code, so I don't think that's it. Any ideas?

No code, no ideas.

http://www.cs.drexel.edu/~ummaycoc/mathgame.tgz

thanks for any help you can give.

~Matt

Back to top
Andrew Thompson
Guest





PostPosted: Tue Nov 30, 2004 1:20 am    Post subject: Re: Swing JPanel PaintComponent Issue Reply with quote

On 29 Nov 2004 15:11:54 -0800, matt wrote:

Quote:
"John McGrath" <ng (AT) jpmcgrath (DOT) net> wrote

On 11/28/2004 at 8:11:49 PM, matt wrote:

Sometimes, though, my application will just hang and not paint
anything - at various `screens' ... I'm not doing any threading stuff
in my code, so I don't think that's it. Any ideas?

No code, no ideas.

http://www.cs.drexel.edu/~ummaycoc/mathgame.tgz

...hmmm. 23 files amounting to 43.5Kb of code.

I don't suppose you have a *short* example that displays the problem?

--
Andrew Thompson
http://www.PhySci.org/codes/ Web & IT Help
http://www.PhySci.org/ Open-source software suite
http://www.1point1C.org/ Science & Technology
http://www.LensEscapes.com/ Images that escape the mundane

Back to top
hiwa
Guest





PostPosted: Tue Nov 30, 2004 4:36 am    Post subject: Re: Swing JPanel PaintComponent Issue Reply with quote

[email]mhm26 (AT) drexel (DOT) edu[/email] (matt) wrote in message news:<13383d7a.0411291511.32c96330 (AT) posting (DOT) google.com>...
Quote:
"John McGrath" <ng (AT) jpmcgrath (DOT) net> wrote

On 11/28/2004 at 8:11:49 PM, matt wrote:

Sometimes, though, my application will just hang and not paint
anything - at various `screens' ... I'm not doing any threading stuff
in my code, so I don't think that's it. Any ideas?

No code, no ideas.

http://www.cs.drexel.edu/~ummaycoc/mathgame.tgz

thanks for any help you can give.

~Matt

Ugh! Nope! Please don't do that.
See http://www.physci.org/codes/sscce.jsp

Back to top
John McGrath
Guest





PostPosted: Tue Nov 30, 2004 5:26 am    Post subject: Re: Swing JPanel PaintComponent Issue Reply with quote

On 11/29/2004 at 6:11:54 PM, matt wrote:

Quote:
http://www.cs.drexel.edu/~ummaycoc/mathgame.tgz

Just looking at the Gui class, I can see that the entire structure of the
program is wrong. You need to do some reading on Swing, the AWT event
model and threads. You can find some good material on that in "The Java
Tutorial" on the Sun web site, but I would also recommend that you take in
a good Swing book.

However, in a nutshell, you need to know two basic rules:

1) Swing is (for the most part) not thread-safe. That means that you need
to update the UI in the Event Dispatch Thread.

2) Swing does painting and other critical functions in the Event Dispatch
Thread, so event handlers must do their work and exit quickly.

This may sound very constraining, but it really is not. You just need to
learn how to put things together.

--
Regards,

John McGrath

Back to top
matt
Guest





PostPosted: Tue Nov 30, 2004 3:16 pm    Post subject: Re: Swing JPanel PaintComponent Issue Reply with quote

"John McGrath" <ng (AT) jpmcgrath (DOT) net> wrote

Quote:
On 11/29/2004 at 6:11:54 PM, matt wrote:

http://www.cs.drexel.edu/~ummaycoc/mathgame.tgz

Just looking at the Gui class, I can see that the entire structure of the
program is wrong. You need to do some reading on Swing, the AWT event
model and threads. You can find some good material on that in "The Java
Tutorial" on the Sun web site, but I would also recommend that you take in
a good Swing book.

However, in a nutshell, you need to know two basic rules:

1) Swing is (for the most part) not thread-safe. That means that you need
to update the UI in the Event Dispatch Thread.

2) Swing does painting and other critical functions in the Event Dispatch
Thread, so event handlers must do their work and exit quickly.

This may sound very constraining, but it really is not. You just need to
learn how to put things together.

So, I only have the one thread doing anything (the Gui Runnable - the
main program is done after main(String[])), so there shouldn't be any
issues with what I did (I think).

I also don't think my event handlers are that inefficient - but I
don't think that's relevant to my problem. It seems that
paintComponent() is not even being called in some cases.

Back to top
Andrew Thompson
Guest





PostPosted: Tue Nov 30, 2004 3:34 pm    Post subject: Re: Swing JPanel PaintComponent Issue Reply with quote

On 30 Nov 2004 07:16:58 -0800, matt wrote:

Quote:
It seems ..

Please do not waste our time with 'seems'. Find out for sure*.

Quote:
...that
paintComponent() is not even being called in some cases.

public void paintComponent(Graphics g) {
// * Put a print statement to check..
System.out.println( "Entered paintComponent()!" );
...

--
Andrew Thompson
http://www.PhySci.org/codes/ Web & IT Help
http://www.PhySci.org/ Open-source software suite
http://www.1point1C.org/ Science & Technology
http://www.LensEscapes.com/ Images that escape the mundane

Back to top
Babu Kalakrishnan
Guest





PostPosted: Tue Nov 30, 2004 3:38 pm    Post subject: Re: Swing JPanel PaintComponent Issue Reply with quote

matt wrote:
Quote:

So, I only have the one thread doing anything (the Gui Runnable - the
main program is done after main(String[])), so there shouldn't be any
issues with what I did (I think).


If the "Gui runnable" is something that is running in a thread that was
started by you, then it _is_ _not_ the Event Dispatch Thread, and you
aren't allowed to do any GUI updates from that thread. There is only a
single thread called the EDT which is used by AWT for its event dispatch
and paint operations, and that is created automatically by the AWT
process.

BK

Back to top
matt
Guest





PostPosted: Tue Nov 30, 2004 9:59 pm    Post subject: Re: Swing JPanel PaintComponent Issue Reply with quote

Andrew Thompson <SeeMySites (AT) www (DOT) invalid> wrote

Quote:
On 30 Nov 2004 07:16:58 -0800, matt wrote:

It seems ..

Please do not waste our time with 'seems'. Find out for sure*.

...that
paintComponent() is not even being called in some cases.

public void paintComponent(Graphics g) {
// * Put a print statement to check..
System.out.println( "Entered paintComponent()!" );
...

So, I had the following:

protected final void paintComponent(Graphics g) {
super.paintComponent(g);
System.out.println(this.getClass().getCanonicalName())

in a class that is a sort of baseclass (extends JPanel) that I extend
for drawing my various screens -- so I was already on that ball - I
said `it seems' because that is what is happening as far as I could
tell (but maybe super.paintComponent(g) was messing up). I'll check
later when I get to that machine to see that - but I don't think that
would cause any issue.

Back to top
matt
Guest





PostPosted: Tue Nov 30, 2004 10:00 pm    Post subject: Re: Swing JPanel PaintComponent Issue Reply with quote

Babu Kalakrishnan <k.a.l.a (AT) sankya (DOT) com> wrote

Quote:
matt wrote:

So, I only have the one thread doing anything (the Gui Runnable - the
main program is done after main(String[])), so there shouldn't be any
issues with what I did (I think).


If the "Gui runnable" is something that is running in a thread that was
started by you, then it _is_ _not_ the Event Dispatch Thread, and you
aren't allowed to do any GUI updates from that thread. There is only a
single thread called the EDT which is used by AWT for its event dispatch
and paint operations, and that is created automatically by the AWT
process.

BK

My thread doesn't call paint - it just instantiates objects that are
subclasses of JPanel that are added to a JFrame -- so I'm not doing
any updating from my thread.

~Me!

Back to top
hiwa
Guest





PostPosted: Wed Dec 01, 2004 12:39 am    Post subject: Re: Swing JPanel PaintComponent Issue Reply with quote

From Gui.java:

This is wrong:

Quote:
new Thread(new Gui(frame)).run();

And you don't call invokeLater() or invokeAndWait() from you
app thread.

Everybody can tell you haven't learn Java basics at all!!

Back to top
John McGrath
Guest





PostPosted: Wed Dec 01, 2004 2:11 am    Post subject: Re: Swing JPanel PaintComponent Issue Reply with quote

On 11/30/2004 at 5:00:43 PM, matt wrote:

Quote:
My thread doesn't call paint - it just instantiates objects that are
subclasses of JPanel that are added to a JFrame -- so I'm not doing
any updating from my thread.

Matt,

Here are some rather simple things you need to listen to and understand:

1) Your code is not going to work the way it is put together.

2) You may think you understand the correct structure and operation of
Swing / AWT programs, but you *really* do not.

3) The people who are telling you this *do* understand Swing and AWT.
At least some of them understand it better than just about anyone you
are likely to meet.

4) People in these newsgroups are willing to spend time helping others,
but those seeking help need to bring themselves to a point where they can
understand what they are being told, without requiring others to write a
book for them. As such, you need to get a good Swing book and study it.

--
Regards,

John McGrath

Back to top
matt
Guest





PostPosted: Wed Dec 01, 2004 3:08 pm    Post subject: Re: Swing JPanel PaintComponent Issue Reply with quote

Quote:
1) Your code is not going to work the way it is put together.

I know it's not. That's why I came here. The fact that it working is
nondeterministic gives me issues.


Quote:
2) You may think you understand the correct structure and operation of
Swing / AWT programs, but you *really* do not.

No - I don't think I understand the correct operation/structure of the
AWT/Swing programs. I try to stay away from Java (it's a *very*
poorly designed beast - not that my current incarnation of its use is
any better).


Quote:
3) The people who are telling you this *do* understand Swing and AWT.
At least some of them understand it better than just about anyone you
are likely to meet.

I don't think I asserted otherwise.


Quote:
4) People in these newsgroups are willing to spend time helping others,
but those seeking help need to bring themselves to a point where they can
understand what they are being told, without requiring others to write a
book for them. As such, you need to get a good Swing book and study it.

So, people said "It may be x" and I said "I don't think it is X
because of Y" - clearly I may not have an understanding of how X and Y
interact in the java model of reality. So I was trying to do what you
said - bring myself to understanding by presenting my view of the
scenario - but you seem to assert otherwise, and it seems like you
came off as quite rude/curt in doing so, something you may wish to
look into considering you are presenting yourself as a facet of a
community (java/swing/awt).

I'm working on a short example to reproduce the error -- I hope the
community can still help me when I have it.

Thanks,

Matthew Maycock

Back to top
Andrew Thompson
Guest





PostPosted: Wed Dec 01, 2004 3:32 pm    Post subject: Re: Swing JPanel PaintComponent Issue Reply with quote

On 1 Dec 2004 07:08:29 -0800, matt wrote:

Quote:
I'm working on a short example to reproduce the error ..

A sterling idea. For tips on preparing an example that will help
others to help you, check the document that hiwa linked to.
( I can personally recommend those tips, since I wrote the document Wink.

--
Andrew Thompson
http://www.PhySci.org/codes/ Web & IT Help
http://www.PhySci.org/ Open-source software suite
http://www.1point1C.org/ Science & Technology
http://www.LensEscapes.com/ Images that escape the mundane

Back to top
Display posts from previous:   
Post new topic   Reply to topic    AppletTalk.com Forum Index -> Java GUI Toolkits All times are GMT
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.