?
Solved

setting  JFrame in the middle of screen.

Posted on 2004-11-30
7
Medium Priority
?
541 Views
Last Modified: 2008-01-09
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);      

...
...
...
+++++++++++++++++++++
0
Comment
Question by:dkim18
  • 3
  • 2
  • 2
7 Comments
 
LVL 86

Assisted Solution

by:CEHJ
CEHJ earned 160 total points
ID: 12710377
You have no components on the frame - don't call pack
0
 
LVL 92

Accepted Solution

by:
objects earned 320 total points
ID: 12710592
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
 

Author Comment

by:dkim18
ID: 12711085
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 92

Expert Comment

by:objects
ID: 12711108
Can't see a problem there, make sure you add them *before* you make the frame visible.
0
 

Author Comment

by:dkim18
ID: 12711150
thanks for telling me that^^
0
 
LVL 92

Expert Comment

by:objects
ID: 12711162
no worries :)
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 12711274
8-)
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Suggested Courses
Course of the Month16 days, 4 hours left to enroll

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question