java 右下角_java – 屏幕右下角的位置

我需要在屏幕上放置JFrame.但我无法让它们出现在屏幕底部的右侧.

请有人解释我如何定位它们,如果你能描述如何做,那就太好了.

这是迄今为止的代码.

//Gets the screen size and positions the frame left bottom of the screen

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

试试下面的例子.请注意0​​7000“如何调整此窗口的大小以适合其子组件的首选大小和布局.”

import java.awt.Dimension;

import java.awt.EventQueue;

import java.awt.GraphicsDevice;

import java.awt.GraphicsEnvironment;

import java.awt.Rectangle;

import javax.swing.JFrame;

import javax.swing.JPanel;

/** @see https://stackoverflow.com/q/9753722/230513 */

public class LowerRightFrame {

private void display() {

JFrame f = new JFrame("LowerRightFrame");

f.add(new JPanel() {

@Override // placeholder for actual content

public Dimension getPreferredSize() {

return new Dimension(320,240);

}

});

f.pack();

f.setDefaultCloSEOperation(JFrame.EXIT_ON_CLOSE);

GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();

GraphicsDevice defaultScreen = ge.getDefaultScreenDevice();

Rectangle rect = defaultScreen.getDefaultConfiguration().getBounds();

int x = (int) rect.getMaxX() - f.getWidth();

int y = (int) rect.getMaxY() - f.getHeight();

f.setLocation(x,y);

f.setVisible(true);

}

public static void main(String[] args) {

EventQueue.invokeLater(new Runnable() {

@Override

public void run() {

new LowerRightFrame().display();

}

});

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值