Reputation: 501
I am developing an application which needs to pop up new JFrame
B with different components, when I click on a button on JFrame
A. How do I achieve that?
I don't want to use the tabs.
Upvotes: 1
Views: 16372
Reputation: 12092
Use a JDialog , problem solved!
See this java tutorial for more help : How to Make Dialogs
Upvotes: 6
Reputation: 6229
One way to approach this would be to create another jFrame and then add a listener onto your button like so:
jFrameNew.setVisible(true);
This way you have a whole new frame to work with. If you want to just have a pop-up message you can also try using the jDialog frames.
Depending on which IDE you are using...for example Netbeans has a gui that makes designing interfaces slightly easier, so you can test out the different frames.
Upvotes: 0
Reputation: 4324
In a nutshell (a simple solution), you register a listener with the JButton and then have the listener perform the tasks you want it to perform:
setVisible(true) for one frame.
setVisible(false) for the other one.
Regards!
Upvotes: 1
Reputation: 285403
I'm not sure why no one has suggested CardLayout yet, but this is likely your best solution. The Swing tutorials have a good section on this: How to use CardLayout
Upvotes: 5