gpt4 book ai didi

java - 在 Swing 中获取当前外观组件背景颜色的正确方法是什么?

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:04:02 24 4
gpt4 key购买 nike

我正在用自己的绘画编写自定义 Swing 组件。我想查询当前外观的组件是否不透明,如果是,它们的背景颜色是什么,以便我的组件也可以使用它。我很难在 Google 上找到它。有人知道吗?谢谢!

最佳答案

这很简单:

public class MyComponent extends JComponent {

public void paintComponent(Graphics g) {

if (this.isOpaque()) {
// Paint background
g.setColor(this.getBackground());
g.fillRect(0,0,this.getWidth(), this.getHeight());
}

g.setColor(this.getForeground());
// Continue painting
}
}

关于java - 在 Swing 中获取当前外观组件背景颜色的正确方法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2710458/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com