This week's book giveaway is in the Cloud/Virtualizaton forum.
We're giving away four copies of Mesos in Action and have Roger Ignazio on-line!
See this thread for details.
Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Work with some windows in one window

 
Jose Pérez
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2584
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Read the section from the Swing tutorial on How to Use CardLayout.
 
Jose Pérez
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2584
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic