Results 1 to 3 of 3
- 06-04-2011, 05:35 PM #1
How do I know what screen my app is currently in?
I've been posting a lot of questions here lately because this has been my best source of information. Thank you to all who have answered my questions. I only hope to return the favor after I become more proficient.
My current problem is how can I get the current screen dimensions of whatever screen, in a multiple screen system, my app happens to be in. The following code snippet is what I do at initial startup of my app and successfully obtains and stores the dimensions of all screens in a system:
When a user presses the help button, I popup a new window containing help information. What I want to do is place the help screen along the right edge of the main window. This could result in the help screen being placed off screen. To prevent this, I need to get the dimensions of the current screen and do some simple math. So far, everything I've tried returns the same screen size no matter where the app main window happens to be. The last thing I tried was:Java Code:GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); GraphicsDevice[] gs = ge.getScreenDevices(); screenSize = new Dimension[gs.length]; for (int i = 0; i < gs.length; ++i) { DisplayMode dm = gs[i].getDisplayMode(); screenSize[i] = new Dimension(); screenSize[i].width = dm.getWidth(); screenSize[i].height += dm.getHeight(); }
Once again, as usual, I must be missing some simple thing somewhere. BTW, I also tried just adding all the screen dimensions and treating it like one big screen but that doesn't work because the screen arrangement has an effect on it. So I really need to know the screen dimensions of the screen where my app is currently running.Java Code:Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
Thanks for any help you can offer.
- 06-04-2011, 08:21 PM #2
Read the API for GraphicsDevice, there's a (bad*) example of placing a JFrame in each screen using GraphicsConfiguration#getBounds().
* bad because it show a Canvas (heavyweight, AWT Component) added to a JFrame. Should have used JFrame with JPanel or Frame with Canvas. Probably an artifact of updating pre-Swing documentation.
db
- 06-04-2011, 10:03 PM #3
Similar Threads
-
new screen
By tha_crazy in forum New To JavaReplies: 4Last Post: 02-16-2011, 10:46 AM -
Can't put the image on the screen??
By nickburris in forum New To JavaReplies: 13Last Post: 02-01-2011, 01:50 AM -
Move from one screen fto other screen
By jprgmr75 in forum CLDC and MIDPReplies: 0Last Post: 01-02-2011, 06:32 PM -
Splash Screen
By madcommu in forum SWT / JFaceReplies: 4Last Post: 09-18-2010, 01:14 PM -
Blank Screen while navigating from one screen to another
By mohana.krishna in forum Java ServletReplies: 0Last Post: 03-03-2009, 05:03 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks