Solved

Multiple JFrame Overlap Problem

Posted on 2009-05-14
13
378 Views
Last Modified: 2013-12-22
Hi there,

I have a problem with 2 JFrames that I display - if I place their windows to overlap each other, and then select the one from behind the other, I then get the contents of the alternate frame showing in the the selected JFrame.

If I then move the misbehaving JFrame around a few times and play around with it, it comes back to normal again.

Any ideas why this would happen?
0
Comment
Question by:TheOwner
  • 5
  • 5
  • 2
13 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 24388343
Sounds like its painting is being inhibited. Are you doing any processing in event handlers?
0
 
LVL 92

Expert Comment

by:objects
ID: 24390643
you have a problem with your gui painting, you either have an exception occurring or you are blocking the painting.

0
 

Author Comment

by:TheOwner
ID: 24391212
Hi there objects,

I do not think I am throwing an exception. I tried searching for blocking painter, etc but I can't find any information on that.

Could you please explain what might block a painting?
0
 

Author Comment

by:TheOwner
ID: 24391217
@CEHJ

My event EventHandlers do very basic things - nothing too intensive at all. They are not being fired off from what I can see though.
0
 
LVL 92

Expert Comment

by:objects
ID: 24391285
can you post an example that demonstrates the problem.
do you do any custom painting?

0
 

Author Comment

by:TheOwner
ID: 24391315
Hi objects,

That is correct - I am using Substance LookAndFeel (I am sure you know it). I don't have any custom painting that I have written myself.

If I turn if off, I still get the problem though. I tried just making test JFrame with a button and another with nothing and I still get the same problem. I just made a new JFrame and added the button, followed by the other JFrame with an empty JPanel.

My theory is this has something to do with my threading, do you think this may be the case?
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 92

Expert Comment

by:objects
ID: 24391343
if you have additional threads you need to ensure you do not update your gui from those threads. All gui updates need to be done from the event dispatch thread.


0
 

Author Comment

by:TheOwner
ID: 24391361
Hi Objects,

I think we're on to something here - that may be the problem. You see, the problem though is my application generates new JComponents on the fly and I don't see a means to have that inside the EDT.

For example, the application listens on the network for particular responses and then generates GUI JComponents - it can only know what and how many to make once the response has been received.

A little off - topic but just checking if you got my mail I sent through your site?
0
 
LVL 92

Accepted Solution

by:
objects earned 250 total points
ID: 24391387
EventQueue has 2 methods you can use invokeLater() and invokeAndWait()

http://helpdesk.objects.com.au/java/how-do-i-update-my-gui-from-any-thread

> A little off - topic but just checking if you got my mail I sent through your site?

A am just in the process of reading my inbox

0
 

Author Comment

by:TheOwner
ID: 24391443
Hi objects,

Well basically I have tried those methods but I still can't understand how to do a dynamic GUI using that methodology. For instance, mine works as follows:

(Pseudocode as it will make it easier to understand)

Network Thread {

while(true) {

read();

if (isGuiInformation) {
JLabel label = new JLabel(<dataFromRead()>)
}

}

}

I can maybe see if I can just use a normal thread instead of a ED Thread.
0
 
LVL 92

Assisted Solution

by:objects
objects earned 250 total points
ID: 24391459

while(true) {

read();

EventQueue.invokeAndWait(new Runnable() {
   public void run() {
        // update gui here
   }
});


0
 
LVL 86

Expert Comment

by:CEHJ
ID: 24392894
See the well-documented SwingWorker class for multiple threading with correct handling of the gui
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
json example 39 130
java  and programming certification ? 4 86
recursion example 16 111
rhino JavaScript import, load 25 66
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…

914 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now