![](/img/trans.png)
[英]Java Swing - How do I make it so that closing a Dialog box doesn't close the entire program?
[英]Java Swing; How do I make it so the program starts on the right most hand of the screen?
默認情況下,我的Swing程序從顯示器的左上角開始。 有沒有辦法讓它突然出現在右側?
那么雙顯示器呢? 我可以讓它在正確的顯示器上彈出嗎?
謝謝。
卡羅
關於使用GraphicsEnvironment
做類似事情有很多問題/答案。
你可以使用GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices()
獲取所有監視器,然后調用GraphicsDevice#getConfigurations
然后調用GraphicsDevice#getConfigurations
GraphicsConfiguration#getBounds
來獲取每個監視器的大小和位置,然后使用你的高中幾何來找到“正確的” “監視器。 (請注意,真正的多顯示器設置可以將它們放在任意位置。)
假設您不想掩蓋任務欄,則應使用getMaximumWindowBounds。
http://www.javabeginner.com/java-swing/java-jframe-class-example
以JFrame為中心
默認情況下,Jframe顯示在屏幕的左上角。 要在指定位置顯示幀,可以在JFrame類中使用setLocation(x,y)方法。 此方法將框架的左上角放置在位置(x,y)。
右上角的偽代碼看起來像這樣:
yourJFrame.setLocation(
GraphicsEnvironment.getMaximumWindowBounds().getWidth() -
yourJFrame.getWidth(), 0);
要在另一個初始位置顯示,請查看JFrame.setLocation()
要在另一個屏幕上顯示,請查看GraphicsEnvironment.getScreenDevices()
中的可用信息。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.