英文:
Dim background when opening JDialog in JFrame?
问题
这可能吗?我尝试设置JFrame的不透明度并设置背景,但效果不好。有没有一些简单而优雅的方法?
英文:
Is that possible. I tried setting opacity of the Jframe and set background but it didn't work out. Is there some easy and elegant way?
答案1
得分: 1
通过将JFrame的glassPane设置为具有半透明背景的可见JPanel,您可以实现此目标:
static void setDimmed(JFrame frame,
boolean dimmed) {
JComponent newGlassPane = new JPanel();
if (dimmed) {
newGlassPane.setBackground(new Color(0x80000000, true));
}
frame.setGlassPane(newGlassPane);
newGlassPane.setVisible(dimmed);
}
英文:
You can achieve this by setting the JFrame’s glassPane to a visible JPanel with a translucent background:
static void setDimmed(JFrame frame,
boolean dimmed) {
JComponent newGlassPane = new JPanel();
if (dimmed) {
newGlassPane.setBackground(new Color(0x80000000, true));
}
frame.setGlassPane(newGlassPane);
newGlassPane.setVisible(dimmed);
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论