Search code examples
javaswingpositioning

Setting frame to start at bottom left in java


Ive got a pretty simple reqeust. Ive a program that displays code runnign from right to left. like a marquee.

Im looking to set the location to bottom left for it to start, instead of the top left.

eg

frame.setLocation(0,0) is top left.
frame.setLocation(0,700) moves it as close as i can to the bottom

something similar to float right would be what i had in mind.

regards, Overtone


Solution

  • One possibility would be to grab the default screen configuration, use that to get the default boundaries of the screen then use that to place the window. Something like:

    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice defaultScreen = ge.getDefaultScreenDevice();
    Rectangle rect = defaultScreen.getDefaultConfiguration().getBounds();
    int x = (int)rect.getMinX();
    int y = (int)rect.getMaxY()-frame.getHeight();
    frame.setLocation(x,y);