我想在Java中设置JToolBar的渐变背景颜色。我能够为JPanel设置这个渐变效果。
谢谢,Sathish
发布于 2011-06-21 20:02:15
与任何其他Swing组件一样,您必须重写其paintComponent(...)方法。例如,
@Override
protected void paintComponent(Graphics g){
// Create the 2D copy
Graphics2D g2 = (Graphics2D)g.create();
// Apply vertical gradient
g2.setPaint(new GradientPaint(0, 0, Color.WHITE, 0, getHeight(), Color.BLUE));
g2.fillRect(0, 0, getWidth(), getHeight());
// Dipose of copy
g2.dispose();
}如果希望通过JToolBar上的组件显示此渐变,则必须在每个组件上调用setOpaque(false)。
https://stackoverflow.com/questions/6424618
复制相似问题