OVERTONE
OVERTONE

Reputation: 12207

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

Upvotes: 2

Views: 3803

Answers (2)

rati
rati

Reputation: 41

This would always place the window above the taskbar...

Dimension scrSize = Toolkit.getDefaultToolkit().getScreenSize();
Insets toolHeight = Toolkit.getDefaultToolkit().getScreenInsets(getGraphicsConfiguration());
 setLocation(Toolkit.getDefaultToolkit().getScreenSize().width - getWidth(), Toolkit.getDefaultToolkit().getScreenSize().height - getHeight());

Upvotes: 4

Michael Berry
Michael Berry

Reputation: 72344

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);

Upvotes: 4

Related Questions