想要用一半红色和一半蓝色来更改 JButton



我想将我的 JButton 背景颜色设置为一半红色和一半蓝色。我可以在不使用图形 2D 的情况下在 java swing 中做到这一点吗?请帮帮我!

你可以通过让它渐变来做到这一点。

buttonGraphics.setPaint(new GradientPaint(
new Point(0, 0), 
Color.RED, 
new Point(0, getWidth()), 
Color.BLUE()));
buttonGraphics.fillRect(0, 0, getWidth(), getHeight());
buttonGraphics.dispose()

最新更新