top button
Flag Notify
    Connect to us
      Facebook Login
      Site Registration Why to Join

Facebook Login
Site Registration
Print Preview

JFrame whose content changes as we click on the different buttons?

+1 vote

I am using Java's Swing here to make a UI application. I have a created a JFrame, with some buttons. When I click on this button, I want a new JFrame with some different content at this place. However, I do not want a new JFrame to load here.
One approach, I know is of setting the visbility of the second JFrame to be True in the actionPerformed(ActionEvent obj) method of the button in the first JFrame. But it again loads a new JFrame and I don't want that.

public class FirstUI extends JFrame {
    JButton but1;
    public FirstUI(){
        but1= new JButton("Click here");

    XYZ obj= new XYZ():

    public class XYZ implements ActionListener{
        public void actionPerformed(ActionEvent obj1){

             // WHAT TO DO HERE  

I only want a single JFrame whose content changes as we click on different buttons. How can I achieve that ?

posted Mar 26, 2013 by Salil Agrawal

Looking for an answer?  Promote on:
Facebook Share Button Twitter Share Button Google+ Share Button LinkedIn Share Button Multiple Social Share Button

Similar Questions
+6 votes

I used a borderLayout, added a JLabel in north then added a jpanel into the center with a grid layout (8,1) and then added two empty panels to make the extra spaces on the far left and right. So my question, is there another way to make these spaces?

Frame I want

Frame I made

Useful Links with Similar Problem
Contact Us
+91 9880187415
#280, 3rd floor, 5th Main
6th Sector, HSR Layout
Karnataka INDIA.