【问题标题】:Creating a rectangle with shadow effect borders [duplicate]创建一个带有阴影效果边框的矩形[重复]
【发布时间】:2020-03-15 11:02:18
【问题描述】:

有没有一种方法可以在我想添加到 JPanel 上的矩形的边缘周围创建阴影效果。

This is how I will be creating the rectangles but I don't know how to add shades around   
the edges


public void paint(Graphics g) {
        super.paintComponents(g);

        g.drawRect(340,315, 200, 120);

        g.drawRect(5,315, 200, 120);


    }

【问题讨论】:

  • 在两条边上使用 drawLine(...) 怎么样?或者,如果您想要更厚的阴影,请在 2 个边缘周围使用 fillRect(...)。覆盖的方法也是paintComponent(...) 而不是paint() 并且您调用super.paintComponent(...)(没有“s”)。阅读Custom Painting 上的 Swing 教程以获取更多信息和工作示例。
  • 内置的borders 都不适合你?

标签: java swing


【解决方案1】:

添加带有阴影边缘的面板,或者您可以在这里寻找解决方案

JPanel Drop Shadow

【讨论】:

    猜你喜欢
    • 2020-03-26
    • 2020-12-29
    • 2012-03-26
    • 2018-10-09
    • 1970-01-01
    • 1970-01-01
    • 2011-08-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多