File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes Panel Visiblity.... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Panel Visiblity...." Watch "Panel Visiblity...." New topic
Author

Panel Visiblity....

Ram Alluri
Greenhorn

Joined: May 15, 2001
Posts: 2
I have small standalone GUI application, which contains four screens. The flow goes from one screen to next screen by pushing a JButton on each screen. Here is the design.
Here are the classes I have:
Main.java
Main extends JFrame {
public static void main(String[] args) {
}
}
FirstScreen.java
FirstScreen extends JPanel {
FirstScreen(Main parent) {}
}
SecondScreen.java
SecondScreen extends JPanel {
FirstScreen(Main parent) {}
}
.... and so on
Each Screen is shown by attaching to the Main.
Problem:
When I go from FirstScreen to SecondScreen, somehow even is not visible( though it is captured behind the screen) on the SecondScreen. Meaning for every action to be visible on the second screen, I have to refresh the screen by minimizing/maximizing it OR by hiding with some other window.
To make it more clear say, If I click a JButton on the SecondScreen, ThirdScreen is not visible. However if I minimize it and maximize again it is visible. It seems to be some issue with the setting the Visibility for the Frame & JPanel.
Can some one help me how do I have to set the visibility for the screens OR is there any better design ?
Whenever I want to show a screen, I do this:
setVisible(false) (for currentScreen)
setVisible(false) (for Main )
setVisible(true) (for the new Screen)
setVisible(true) (for Main)
John Zukowski
Author
Ranch Hand

Joined: Mar 29, 2001
Posts: 88
If I had to guess, you're changing attributes outside the main event thread.
------------------
John Zukowski Author of "Definitive Guide to Swing for Java 2" and "Java Collections"


John Zukowski Author of <a href="http://www.amazon.com/exec/obidos/ASIN/189311578X/ref=ase_electricporkchop/107-7882751-0234939" target="_blank" rel="nofollow">"Definitive Guide to Swing for Java 2"</a>,<br /><a href="http://www.amazon.com/exec/obidos/ASIN/1893115925/ref%3Dase%5Felectricporkchop/102-5437230-7785719" target="_blank" rel="nofollow">"Java Collections"</a> and <a href="http://www.amazon.com/exec/obidos/ASIN/1893115984/ref%3Dase%5Felectricporkchop/102-5437230-7785719" target="_blank" rel="nofollow">"Learn Java with JBuilder 6"</a>
Ram Alluri
Greenhorn

Joined: May 15, 2001
Posts: 2
Can you please elaborate a bit ?
John Zukowski
Author
Ranch Hand

Joined: Mar 29, 2001
Posts: 88
Swing isn't thread-safe. You must only change their attributes within the event thread. Look at using the invokeLater() and invokeAndWait() methods and read up on Swing threads. http://java.sun.com/docs/books/tutorial/uiswing/overview/threads.html offers an online resource for this.
------------------
John Zukowski Author of "Definitive Guide to Swing for Java 2" and "Java Collections"
Laurent Leonard
Ranch Hand

Joined: May 15, 2001
Posts: 35
Maybe you can take a look at CardLayout.
If I guess what you want to do, you will find the right and the simplest way to make it.


Laurent LEONARD
 
 
subject: Panel Visiblity....
 
Similar Threads
Problem with ActionListener and JButtons (harder than it first seems
calling a JPanel page
Simple JPanel question....
Opening a java file as popup window
Dynamic Swing