【发布时间】: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 都不适合你?