aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Work with some windows in one window Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Work with some windows in one window" Watch "Work with some windows in one window" New topic
Author

Work with some windows in one window

Jose Pérez
Greenhorn

Joined: Jul 19, 2009
Posts: 10
Hi guys, I´m making an interface for some math exercises. I have a window per exercise (3 now) and now I want to work with all of them in one single window, by clicking a button in the main window, and replacing the content of it with the content of the window of the exercises choose.

But with my actual skills, what I get is a new window over the main. I think I should change the constructor of the exercises classes, but I don´t know how.

¿How can I fix this?


The code for each exercise window (all whit the same structure) is this:



And the code for the three JButton of the main window is:





Cheers.
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2200
    
    7
Read the section from the Swing tutorial on How to Use CardLayout.
Jose Pérez
Greenhorn

Joined: Jul 19, 2009
Posts: 10
Thanks for the point Rob. In the CardLayout tutorial, I found the JTabbedPane, that I think its more suitable for my scenario.

But now I get a similar problem, for each exercise I put in the tabbedpane, I got a blank window under the main window.

In the image, I have put one exercise (tab 1, I don´t modified the title), and that is the blank window under I get:



¿Is the problem then in the classes constructor I put above?
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2200
    
    7
Thats the way layout managers work. By default a JFrame uses a BorderLayout. When you add the tabbed pane to the center of the BorderLayout, the tabbed pane will now occupy all the space available in the frame. If this is not what you want the use (for example):



to see the difference.



Jose Pérez
Greenhorn

Joined: Jul 19, 2009
Posts: 10
Sorry Rob, I think I expressed myself wrong ( I´m from Spain)

The point its that the program generates a blank window under the main program for each exercise class of mine that I add to the main program, like I pointed in the image:



That means, I have 3 blank windows when I execute my complete main program with my three exercises together.

¿What you say is that is the normal thing? because if it is, I prefer to do 3 separated jars.

Jose Pérez
Greenhorn

Joined: Jul 19, 2009
Posts: 10
I finally found the solution

Then, it´s just simple like comment the .setVisible(true) in the frames of the classes that you are going to put in one single window in a main program.

Cheers.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Work with some windows in one window