想要做好组件 心一定要细, 例如ScrpllPane得右下角Component 都要对着渐变一下.
但一定要首先判断 用户是否设置了右下角Component
if (scrollPane.getCorner(ScrollPaneConstants.LOWER_RIGHT_CORNER) == null) {
Component component = new JLabel("") {
@Override
protected void paintComponent(Graphics g) {
Graphics2D g2 = (Graphics2D) g;
Paint oldPaint = g2.getPaint();
Rectangle bounds = getBounds();
Paint backgroupRectPaint = new GradientPaint(0, 0, new Color(216, 216, 216),
bounds.width, bounds.height, new Color(152, 152, 152));
g2.setPaint(backgroupRectPaint);
g2.fillRect(0, 0, bounds.width, bounds.height);
g2.setPaint(oldPaint);
}
};
scrollPane.setCorner(ScrollPaneConstants.LOWER_RIGHT_CORNER, component);
}
在代码里附带了中文注释.详细可以下载代码看,
下载地址:
ScrollBarDemo