本文介绍了JPanel投影的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 JPanel 元素,我想为它添加一个阴影,我怎样才能为元素添加一个漂亮的褪色阴影?我是否需要使用外部库或是否有可以使用的内置库?

I have a JPanel element and I would like added a drop shadow to it, how can I add a nice faded drop shadow to the element? Do I need to use external libraries or is there something that is built in that I can use?

示例:

推荐答案

所以我查看了,它扩展了JPanel并且能够实现结果我正在寻找以下代码:

So I looked into swingx which extends JPanel and was able to achieve the results I was looking for with the following code:

public class Canvas extends JXPanel{

    public Canvas(){
        DropShadowBorder shadow = new DropShadowBorder();
        shadow.setShadowColor(Color.BLACK);
        shadow.setShowLeftShadow(true);
        shadow.setShowRightShadow(true);
        shadow.setShowBottomShadow(true);
        shadow.setShowTopShadow(true);
        this.setBorder(shadow);
    }
}

结果:

这篇关于JPanel投影的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-22 16:39