Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set JFrame to center of Screen in NetBeans

I am developing a java swing desktop application with NetBeans and I want to set the JFrame to the centre of the screen.

from the net I understand that I can use

setLocationRelativeTo(null);

to set the frame to the centre But i am unable to insert the code into the NetBeans IDE because both the frame.pack() and frame.setVisible() are generated codes of the NetBeans 7 IDE and it will not permit any code insertion between the two methods.

I need to to obtain the following :

frame.pack() 
setLocationRelativeTo(null);
frame.setVisible()

Any suggestion on how to fix the problem?

like image 939
CodeAngel Avatar asked Apr 04 '13 13:04

CodeAngel


2 Answers

Properties ->Code -> check out Generate Center

like image 107
user2263202 Avatar answered Nov 02 '22 09:11

user2263202


Is setVisible() on generated code? Strange. Anyway, you can right click the JFrame in Navigator and select Properties. Go to Code and select it to do nothing. Then manually insert you code after initComponents() in the JFrame constructor.

like image 28
Jean Waghetti Avatar answered Nov 02 '22 09:11

Jean Waghetti