Can't center jdialog in jframe [Java] : I can't center my jdialog in my jframe. I've tried to do this but it doesn't work:
   


     public Window(String title) {
    		panel = new JPanel();
    		this.setLocationRelativeTo(Main.instance.frame);
    		this.setModalityType(Dialog.ModalityType.APPLICATION_MODAL);
    		this.setLayout(new GridLayout());
    		this.setResizable(false);
    		this.setPreferredSize(new Dimension(300, 400));
    		this.pack();	
    		this.add(panel);
    		this.setTitle(title);
    	}

Tell me if you need any more code! Thanks for your help!