Swing不丑系列:ScrollPane
今天上班的路上碰到JScrollPane 他非常憤怒,吹著胡子問我:喂!什么時候才能輪到我??我已經平淡很久了.
其實不能怪我..他是一個麻煩的家伙..相對于JButton JComboBox等一些簡單組件來說.
但看在 默默的為Swing滾動的份上..嘗試讓他從我手里,成為一個帥哥.

其實不能怪我..他是一個麻煩的家伙..相對于JButton JComboBox等一些簡單組件來說.
但看在
JScrollPane
|----------------------------------------------------------------------------------------|
版權聲明 版權所有 @chensiyu
引用請注明來源
版權聲明 版權所有 @chensiyu
引用請注明來源
www.aygfsteel.com/chensiyu04
本文由 陳思羽 于 2011年8月24號 出品..
|----------------------------------------------------------------------------------------|
想要做好組件 心一定要細, 例如ScrpllPane得右下角Component 都要對著漸變一下.
但一定要首先判斷 用戶是否設置了右下角Component
在代碼里附帶了中文注釋.詳細可以下載代碼看,
下載地址:ScrollBarDemo
但一定要首先判斷 用戶是否設置了右下角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);
}
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
posted on 2011-08-25 16:35 相信 閱讀(3351) 評論(4) 編輯 收藏 所屬分類: Swing文章