setting JFrame in the middle of screen.

Hello!

I am trying to set JFrame in the middle of screen, but I see minimized window even though i used setSize method. Is there anything wrong this code?

thanks in advance.
+++++++++++++++++++++++++



public extractHead(String drive) {
...
...
        sbjFrame = new JFrame("Rename Subject Folder Frame");
      container = sbjFrame.getContentPane();
      
          Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
          int w = 550;
          int h = 400;
          int x = ( (d.width - w) / 2);
          int y = ( (d.height - h) / 2);

          sbjFrame.setBounds(x, y, w, h);
          
          sbjFrame.setSize(new Dimension(600, 600));
              
          //sbjFrame.setSize(600, 600);
          
          sbjFrame.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
          
            Runnable showFrame = new Runnable() {
                      public void run() {
                            sbjFrame.pack();
                              sbjFrame.setVisible(true);
                      }
            };
            SwingUtilities.invokeLater(showFrame);      

...
...
...
+++++++++++++++++++++
dkim18Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

CEHJCommented:
You have no components on the frame - don't call pack
0
objectsCommented:
public extractHead(String drive) {
...
...
        sbjFrame = new JFrame("Rename Subject Folder Frame");
        container = sbjFrame.getContentPane();
     
         sbjFrame.setSize(600, 600);
         sbjFrame.setLocationRelativeTo(null);        
             
         sbjFrame.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
         sbjFrame.setVisible(true);
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
dkim18Author Commented:
I added compenets like this. Why they are  not showing up on the frame?
 
container.setLayout(new BorderLayout());
container.add(instrucitonPanel, BorderLayout.NORTH);
...
...
container.add(buttonPanel, BorderLayout.SOUTH);
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

objectsCommented:
Can't see a problem there, make sure you add them *before* you make the frame visible.
0
dkim18Author Commented:
thanks for telling me that^^
0
objectsCommented:
no worries :)
0
CEHJCommented:
8-)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.