打开 JFrame 中的 JDialog 时,背景变暗?

huangapple go评论74阅读模式
英文:

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

huangapple
  • 本文由 发表于 2020年8月26日 06:09:02
  • 转载请务必保留本文链接:https://go.coder-hub.com/63587779.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定