Question: Is it possible to include a jpanel into an container from another java file? Let suppose I have 2 java files `fileA.java` and `fileB.java`. And I want to add the entire display content of `fileB.java` inside a container in `fileA.java`. Is this possible? Just a confusion running in for a very long time. Thanks in advance.

Answer: 
You could make the other file/cass `extends JPanel` and then since it *is* a JPanel, you can add it to any other file. For example:

FileA.java

```
public class FileA {
    public FileA() { 
        JFrame jf = new JFrame();
        jf.setLayout(new BorderLayout());

        FileB b = new FileB();

        jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        jf.setBounds(100,100,800,600);
        jf.setVisible(true);

        add(b, BorderLayout.CENTER);
    }
    public static void main(String[] args) {
        new FileA();
    }
}

```

FileB.java

```
public class FileB extends JPanel {
    public FileB() { 
        setLayout(new BorderLayout());
        add(new JLabel("Example"), BorderLayout.CENTER);
    }
}

```

Or you can simply have a JPanel be a field in another file and access it with a getter method.

Example:

FileC.java

```
public class FileC {

    private JPanel panel;

    public FileC() {
        panel = new JPanel();
        panel.add(new JLabel("Example 2"));
    }

    public JPanel getPanel() {
        return panel;
    }

}

```
Yes, you can.

1- If `fileB` class extends `JPanel`, then create an instance of `fileB` and add it to whatever container you have:

```
fileB panel = new fileB();
container.add(panel);

```

2- If `fileB` has a JPanel as a field, then you need to access it either by itself if it's public field, or by a getter method otherwise:

```
fileB f = new fileB();
JPanel panel = f.getPanel(); // or f.panel if the panel is a public field
container.add(panel);

```