Java窗口居中

在J2SE中,我们可以通过计算屏幕的大小和窗口的大小,然后调整窗口的位置达到让窗口居中的效果。
实例1:<wbr style="line-height:25px"><div style="line-height:25px"> <div style="line-height:25px; color:rgb(51,102,255)"> JFrame fileDeleter=new FileDeleter();</div> <div style="line-height:25px"> <span style="color:#3366FF; line-height:25px"> </span><span style="color:#993300; line-height:25px">Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();</span> </div> <div style="line-height:25px; color:rgb(51,102,255)"> Dimension frameSize =fileDeleter.getSize();</div> <div style="line-height:25px; color:rgb(51,102,255)"> if (frameSize.height &gt; screenSize.height) {</div> <div style="line-height:25px; color:rgb(51,102,255)"> frameSize.height = screenSize.height;</div> <div style="line-height:25px; color:rgb(51,102,255)"> }</div> <div style="line-height:25px; color:rgb(51,102,255)"> if (frameSize.width &gt; screenSize.width) {</div> <div style="line-height:25px; color:rgb(51,102,255)"> frameSize.width = screenSize.width;</div> <div style="line-height:25px; color:rgb(51,102,255)"> }</div> <div style="line-height:25px"> <span style="line-height:25px; color:rgb(51,102,255)"> </span><span style="color:#993300; line-height:25px">fileDeleter.setLocation((screenSize.width - frameSize.width) / 2,</span> </div> <div style="line-height:25px"><span style="color:#993300; line-height:25px"> (screenSize.height - frameSize.height) / 2);</span></div> <div style="line-height:25px; color:rgb(51,102,255)"> fileDeleter.setVisible(true);</div> </div> </wbr>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值