0

I am creating a application and I need help (duh). The thing I need help with is the .setLocation(x,y); and .setSize(); I know how to use both, but if I make my screen resolution less, the location of the JFrame is outside of the screen, and the size is too big! I know the problem, the JFrame size and location does not automatically adjust, and thats what I need help with. Also, take note I havent tried to seen what would happen if the screen resolution is bigger then 1600 X 900 (my screen resolution)

(also the reason I dident show code is because I have a TON of different classes in my project and it would be WAY to hard. Plus, you dont need code to answer this question im pretty sure (but if you do need code to answer it sorry))

My screen resolution: 1600 X 900

Link to the program (do not sell it or copy it and hand it out!) http://www.mediafire.com/download/fm8nxv3wcmmclmo/Gadgets.jar

Thanks for the help!

Jbot
  • 1
  • 2
  • There are LOT's of possibilities, consider using `pack` to pack the window around the contents of the frame instead. Use `JFrame#setExtendedState` to maximize the window, which will be controlled by the OS, you could also use `GraphicsDevice` and `java.awt.Toolkit` to calculate the "safe" bounds of the current device, for [example](http://stackoverflow.com/questions/32555329/java-get-maximized-state-window-size/32555450#32555450) – MadProgrammer Dec 08 '15 at 00:29
  • 1
    I just googled "get screen size java" and first hit was this: http://stackoverflow.com/questions/3680221/how-can-i-get-the-monitor-size-in-java – Taelsin Dec 08 '15 at 00:29
  • Agreed with @Taelsin - you probably don't worry for cases when screen resolition is adjusted after you show your Frame and for initial placement - you can get dimensions of the screen to calculate initial position. – Dmitry Dec 08 '15 at 00:32
  • So what your saying I should do, is get the screen size with the java.awt.Toolkit then add a if statement to decide where each JFrame is placed and the size it is? – Jbot Dec 08 '15 at 00:43
  • @Jbot Well if you want your frame to be in the center of the screen always you should do something like `.setLocation(screenWidth/2 - frame.getWidth()/2, screenHeight/2 - frame.getHeight()/2)`. This should roughly center your frame in the center of the screen on just about any resolution big enough to hold your frame. – Taelsin Dec 08 '15 at 00:57
  • Thanks but I dont want it in the center. – Jbot Dec 08 '15 at 01:49

0 Answers0