public class FadingLayer extends JPanel {
public FadingLayer(JPanel panel) {
// when set to "insets 0 0 0 0", shows the FadingPanel without fading.
setLayout(new MigLayout("insets 1 0 0 0"));
add(panel,"dock center");
setOpaque(false);
}
@Override
public void paintComponent(Graphics arg0) {
Graphics2D graphics = (Graphics2D) arg0;
AlphaComposite alpha = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, opacity);
graphics.setComposite(alpha);
graphics.setColor(getBackground());
graphics.fillRect(0, 0, getWidth(), getHeight());
}
}
这是我放置一些褪色效果的面板。不透明度使用摇摆的 Timer 类更新。问题是当所有插入值都设置为 0 计时器工作但我只看到最终结果没有任何褪色效果。但是,即使其中一个插图设置为某个非零值,我也可以看到褪色效果。怎么了,求救?
编辑:
当面板(添加到FadingPanel
)获取完整区域时会发生这种情况。那是什么时候FadingPanel
设置为-->
setLayout(new BorderLayout());
add(panel,BorderLayout.CENTER);
或者
setLayout(new MigLayout("insets 0 0 0 0"));
add(panel,"dock center");