0

Let's say i have two forms such as a.java and b.java. There is a button inside a.java that creates a b object,hides itself and opens b.java. What i want is to show a.java again after i close b.java. Could anyone give me a simple example about this situation?

EDIT: Let me give an example about my situation. I have a chart like this: enter image description here

When i click one of the values, a new pieChart pops up, gives detailed information about the value. I can look any numbers of values with opening new JFrames. So, i think JTabbedPane can't solve my problem.

Community
  • 1
  • 1
AloneInTheDark
  • 938
  • 4
  • 15
  • 36

1 Answers1

3

This is a perfect situation for a CardLayout, where panels will be "layered" and you can easily navigate through them using methods like show(), previous(), next()

See more at How to use CardLayout

You can also see a simple example here and if you happen to be using Netbeans GUI Builder you can see how to use CardLayout with the diesign view here

Also see The Use of Multiple JFrames, Good/Bad Practice?. The popular answer is NO. CardLayout seems to fit the bill for your situation.

Community
  • 1
  • 1
Paul Samsotha
  • 205,037
  • 37
  • 486
  • 720
  • 1
    I believe he wants a new JFrame to be shown after another one has been closed. – rogue-one Mar 06 '14 at 09:27
  • @mig-25foxbat but he also said he want the other to appear back. This is more suited for `CardLayout`, than using multiple frames. – Paul Samsotha Mar 06 '14 at 09:28
  • wokay, I removed my answer, the title of the question was quite misleading. – rogue-one Mar 06 '14 at 09:29
  • @peeskillet But what about the situation that i need to create more than one JFrame? I need to monitor more than one servers in my case. – AloneInTheDark Mar 06 '14 at 09:34
  • Seems like a `JTabbedPane` might be suitable for that. `CardLayout` and `JTabbedPane` work very similar, just `JTabbedPane` has visible tabs to navigate and `CardLayout` you can create your own buttons to navigate. – Paul Samsotha Mar 06 '14 at 09:35
  • @AloneInTheDark so when you open the new frame, it's all new data, is that what your saying? What about when you navigate back to the old frame, will that be new data too or still the old data? – Paul Samsotha Mar 06 '14 at 09:44
  • it will be the old data. – AloneInTheDark Mar 06 '14 at 09:45
  • @AloneInTheDark What's wrong with just using a modal `JDialog`? I guess I'm wondering why do you need to make the first frame not visible? If you use a modal `JDialog` only that dialog will be accessible until you close it. – Paul Samsotha Mar 06 '14 at 09:46
  • You're right. I guess i need to make this problem more clear, with the links that you added. Will ask a new question with more specific situation about this. – AloneInTheDark Mar 06 '14 at 09:53