How to set JFrame to appear centered regardless of monitor resolution

0 votes
While working with Java, I find it hard to position my main window in the center of the screen when I start the application.

It doesn't have to be vertically centered, horizontal alignment to be the most important goal for me. But vertical alignment is also welcome.
May 7, 2020 in Java by kartik
• 37,520 points
620 views

1 answer to this question.

0 votes

Hello kartik,

You can  always did it in this way:

Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
this.setLocation(dim.width/2-this.getSize().width/2, dim.height/2-this.getSize().height/2);

where this is the JFrame involved.

Thank You!!

answered May 7, 2020 by Niroj
• 82,840 points

Related Questions In Java

0 votes
1 answer

How to set selected value of jQuery Select2?

The third parameter of the new Option ...READ MORE

answered May 30, 2022 in Java by gaurav
• 23,260 points
40,417 views
0 votes
1 answer

How to get the number of digits in an int?

You can find out the length of ...READ MORE

answered May 14, 2018 in Java by Akrati
• 3,190 points
950 views
0 votes
1 answer

How to set a timer in Java?

To work on timer in java, you ...READ MORE

answered May 16, 2018 in Java by Daisy
• 8,140 points
1,217 views
0 votes
1 answer

How to set Encoding in Java ?

Unfortunately, the file.encoding property has to be specified as ...READ MORE

answered May 29, 2018 in Java by Rishabh
• 3,620 points
16,239 views
0 votes
2 answers
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 7, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 4,434 views
0 votes
1 answer
0 votes
1 answer

How can I set JFrame to appear centered, regardless of monitor resolution?

Hello @kartik, Use setLocationRelativeTo(null) This method has a special effect ...READ MORE

answered Apr 21, 2020 in Java by Niroj
• 82,840 points
1,711 views
0 votes
1 answer

How to set AUTO-SCROLLING of JTextArea in Java GUI?

Hii kartik, When you click anywhere over JTextArea, ...READ MORE

answered Apr 21, 2020 in Java by Niroj
• 82,840 points
2,467 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP