Results 1 to 3 of 3
  1. #1
    Join Date
    Feb 2011
    Location
    Florida
    Posts
    60
    Rep Power
    0

    Default 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:

    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();
            }
    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:
    Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
    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.

    Thanks for any help you can offer.

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,189
    Rep Power
    19

    Default

    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

  3. #3
    Join Date
    Feb 2011
    Location
    Florida
    Posts
    60
    Rep Power
    0

Similar Threads

  1. new screen
    By tha_crazy in forum New To Java
    Replies: 4
    Last Post: 02-16-2011, 10:46 AM
  2. Can't put the image on the screen??
    By nickburris in forum New To Java
    Replies: 13
    Last Post: 02-01-2011, 01:50 AM
  3. Move from one screen fto other screen
    By jprgmr75 in forum CLDC and MIDP
    Replies: 0
    Last Post: 01-02-2011, 06:32 PM
  4. Splash Screen
    By madcommu in forum SWT / JFace
    Replies: 4
    Last Post: 09-18-2010, 01:14 PM
  5. Blank Screen while navigating from one screen to another
    By mohana.krishna in forum Java Servlet
    Replies: 0
    Last Post: 03-03-2009, 05:03 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •