CodeAngel CodeAngel - 2 years ago 268
Java Question

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


to set the frame to the centre
But i am unable to insert the code into the NetBeans IDE
because both the

and frame.setVisible()

are generated codes of the NetBeans 7 IDE
and it will not permit any code insertion between the two methods.
to obtain the following :


Any suggestion on how to fix the problem.

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download