JPanel说不透明是什么意思? [英] JPanel said to be opaque what does that mean?

查看:295
本文介绍了JPanel说不透明是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Swing JPanel中说不透明,这是什么意思?

In Swing JPanel said to be opaque, what does that mean?

JPanel VS JComponent与opaque相比如何比较?

Also how JPanel VS JComponent compared in relation to opaque?

如果可能,请简单说明,因此我对GUI编程不是很有经验。

Please explain if possible in simple terms, hence i am not very experienced in GUI programming.

提前感谢您的帮助

推荐答案

不透明在Swing中有一个非常具体的含义 - 它意味着组件完全绘制其范围内的整个区域(参见 setOpaque javadoc

Opaque has a very specific meaning in Swing - it means that the component fully paints the full area within it's bounds (see the setOpaque javadoc)

这主要用于确定是否需要重新绘制当前组件后面的组件。

This is used primarily to determine whether it is necessary to repaint components behind the current component.


  • 如果isOpaque为true,那么在
    之后重新绘制组件后面的任何
    是不必要的(因为它会
    只是被覆盖),因此
    背景图可能会被省略,因为
    是优化。

  • 如果isOpaque为false,那么它表示
    该组件正在实施一些透明度
    效果 - 例如绘制中间有半透明窗口的组件,或绘制非矩形组件

如果您正在创建自己的组件JComponent和setOpaque为true但不遵守合同(即尽管声称不透明,但您没有在边界内绘制完整区域)然后由于背景未重绘而可能会得到意外结果。

If you are creating your own JComponent and setOpaque to true but do not honour the contract (i.e. you do not draw the full area within the bounds despite claiming to be opaque) then you may get unexpected results due to the background not being redrawn.

这篇关于JPanel说不透明是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆