0

My GUI window is opening but nothing is being displayed. By printing out my mainPanel and graphPanel, I can deduce that it's not taking my border values.

I'm new to GUI, can someone help me out.

public class MainGUI extends JFrame{

    public static void main(String [] args){
        JFrame frame = new MainGUI("Title");
        frame.setVisible(true);
    }

    public MainGUI(String title){
        super(title);

        JPanel mainPanel = new JPanel();
        JPanel graphPanel = new JPanel();
        int w = 200;
        int h = 200;
        System.out.println(mainPanel);
        mainPanel.setBorder(BorderFactory.createEmptyBorder(20, 45, 50, 20)); //Create panel Border
        System.out.println(mainPanel);
        graphPanel.setBorder(BorderFactory.createEmptyBorder(0,0,0,0));

        graphPanel.setLayout(new GridLayout(1, 1));
        System.out.println(graphPanel);

        ....
        ....
Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
  • 3
    Did you add the panels to your frame? You should do `getContentPane().add(mainPanel, BorderLayout.SOUTH); getContentPane().add(graphPanel, BorderLayout.CENTER);`. Then you should call `pack()` or `setSize` and only then `setVisible()`. – Alexey Ivanov Feb 21 '22 at 21:48
  • 3
    It's not directly related to your question but you should not extend `JFrame` unless you extending the functionality of `JFrame`. See [Extends JFrame vs. creating it inside the program](https://stackoverflow.com/q/22003802/572834). – Alexey Ivanov Feb 21 '22 at 21:51

0 Answers0