i have alot of forms , when i press in button that's open the other form in new one
how i can make it open in the same form & not open it in new one

Recommended Answers

All 3 Replies

What do you mean by a "form"? Is it a window?

you have to have nested JFrames. I am assuming you are wanting to do something like photoshop, where a new document is made, but it is just a floating form inside the photoshop window. For that, you have to add the JFrame of the form you want to open, into the contentPane of the current or (master) JFrame. So if I have 2 frame, frame1 being the main, frame2 is what the button opens, in the button action listener, do this:

fram1.getContentPane().add(frame2);

Make sure frame2 has proper bounds set using frame2.setBounds(params); Also, make sure that frame1 has a proper layout, either null or a specific one, if you use null, then your program will use coordinates :). Good luck! Hope this helped!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.