想要做好組件 心一定要細(xì), 例如ScrpllPane得右下角Component 都要對著漸變一下.
但一定要首先判斷 用戶是否設(shè)置了右下角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);
}
在代碼里附帶了中文注釋.詳細(xì)可以下載代碼看,
下載地址:
ScrollBarDemo