Thursday, January 2, 2014

Java Desktop Application using Netebans: How to position the form in the center screen?

In design mode:
select your JFrame(on Design mode), and then go to  Properties, Bindings,Events, Code. 
We need "Code" and set properties Generate Center (true) that's all. 


--
Another way through code:
 
JFrame frame = new JFrame("FooRendererTest");
  frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  frame.getContentPane().add(mainPanel); // or whatever...
  frame.pack();
  frame.setLocationRelativeTo(null);  // *** this will center your app ***
  frame.setVisible(true);

No comments: