• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

Panel Visiblity....

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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)
 
Author
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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"
 
Ram Alluri
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you please elaborate a bit ?
 
John Zukowski
Author
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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"
 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!