java设置窗口不可移动_Java – JDialog不可移动
什么代碼有助于使JDialog無法移動?我看了兩個選項:
> setUndecorated(true);哪個有效,但刪除了所有的裝飾.
> addComponentListener并覆蓋componentMoved()方法,這會導(dǎo)致JDialog隨后在移動時調(diào)用induEpilepticSeizure().
有任何想法嗎?
解決方法:
我的第一直覺是 – 你不能,除非你使用setUndecorated(真)…你可以在那里手動放一些裝飾,但是,嗯,唉!
因此,如果你想要原生裝飾并且你想要它不可移動而沒有使用組件監(jiān)聽器的可怕閃爍,我想你不能.
您可以手動創(chuàng)建一個邊框,看起來像默認(rèn)邊框…這是一個如何做的例子,雖然我有意讓邊框看起來像你整天看到的最丑陋的東西.您需要找到BorderFactory調(diào)用的正確組合才能實現(xiàn)您想要的功能.
public static void main(String[] args) throws InterruptedException {
JDialog frame = new JDialog((Frame) null, "MC Immovable");
frame.setUndecorated(true);
JPanel panel = new JPanel();
panel.setBorder(BorderFactory.createEtchedBorder(Color.GREEN, Color.RED));
panel.add(new JLabel("You can't move this"));
frame.setContentPane(panel);
frame.pack();
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
frame.setVisible(true);
}
標(biāo)簽:java,swing,jdialog
來源: https://codeday.me/bug/20190521/1147676.html
總結(jié)
以上是生活随笔為你收集整理的java设置窗口不可移动_Java – JDialog不可移动的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 小米12下周发布!雷军公开发话:高端要对
- 下一篇: java更新数据库错误就回滚_Java