Reputation: 328
I am new in J2SE, I am using Java Swing to create J2SE application. The JFrame
can pick and drag at any where on screen but I want to restrict frame to do not reach out from desktop screen.
How to enforce the drag restriction?
Note: The code must work for all type of O.S.(Window, Linux, Mac)
I found help from net but that code is not supportable for all type of O.S.
Upvotes: 1
Views: 401
Reputation: 2841
You will need to know size of the screen , and size of JFrame.
Toolkit.getDefaultToolkit().getScreenSize();
Use thread to scan for location of JFrame on screen. CONSTANTLY / Daemon
Find the location/Position of JFrame in the window
If user gets to corner of the screen, do some math.Set your JFrame ot latest valid location or to center of the screen.
How to set JFrame to appear centered, regardless of monitor resolution?
Bud for the love of sanity , dont do this. Just let user move it where he wants it.If any software woud do this to me i woud consider it borderline Malware sincei use multimonitor setup, and this is not acceptable for me.
Upvotes: 1