• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Work with some windows in one window

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Rancher
Posts: 3324
32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Rancher
Posts: 3324
32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic