• 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
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Jj Roberts
  • Tim Holloway
  • Piet Souris
Bartenders:
  • Himai Minh
  • Carey Brown
  • salvin francis

sharing Panel between frames

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I would like to share a panel between two frames. How do I do that?

In detail, I have a panel, that has the controls(move control and position info) for a motor. In main frame, I display only the position information from the panel and make the other controls invisible. When a user wants to move motor, he clicks a button on this frame. On the button control, I create a new frame and pass the panel to the new frame and make all controls(move and position info) visible. Then the user can move the motor and when he is done can clos the new frame to revert back to the main frame. The problem is when I revert back to the main frame the panel is not there any more even if I try to repaint. How do I solve this problem?

I also have one more question. For the above problem is it okey to use multiple frames? what do you guys think. One other idea is to use a single frame and change the content pane of ythe frame with the motor controls when I click a button. But the problem here is the code will be cluttered with this controls for multiple panels.

Thankyou
 
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The rule is that you can add a component to only one container. If you add a component to one container and then add it to another, it is removed from the first and added to the second. You could pass the component around from one JFrame to another but this seems inelegant. For options you could launch a JDialog to show the controls and to get user input. You could add a control panel to your JFrame and use the button to toggle it visible/invisible. Swing offers the JTabbedPane that can be useful here. Another option is the AWT CardLayout used here:
reply
    Bookmark Topic Watch Topic
  • New Topic