Swing不丑系列:JComboBox(二)

2014-11-24 00:38:46 · 作者: · 浏览: 1
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
int width = (int) this.getPreferredSize(c).getWidth()
+ arrow.getWidth() - 2;
int height = 0;
int heightOffset = 0;
if (comboBox.isPopupVisible()) {
heightOffset = 5;
height = (int) this.getPreferredSize(c).getHeight();
arrow.setIcon(XUtil.defaultComboBoxArrowIcon_Into);
} else {
heightOffset = 0;
height = (int) this.getPreferredSize(c).getHeight() - 1;
arrow.setIcon(XUtil.defaultComboBoxArrowIcon);
}
if (comboBox.isFocusable()) {
g2.setColor(new Color(150, 207, 254));
}
g2.drawRoundRect(0, 0, width, height + heightOffset,ARCWIDTH,ARCHEIGHT);
}

public void paintCurrentValue(Graphics g, Rectangle bounds, boolean hasFocus) {
Font oldFont = comboBox.getFont();
comboBox.setFont(XUtil.defaultComboBoxFont);

super.paintCurrentValue(g, bounds, hasFocus);
comboBox.setFont(oldFont);
}

public Dimension getPreferredSize(JComponent c) {
return super.getPreferredSize(c);
}

public boolean isBoundsLight() {
return boundsLight;
}

public void setBoundsLight(boolean boundsLight) {
this.boundsLight = boundsLight;
}

protected ComboPopup createPopup() {
ComboPopup popup = new BasicComboPopup(comboBox) {
protected JScrollPane createScroller() {
IScrollPane sp = new IScrollPane(list,
ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
sp.setHorizontalScrollBar(null);
return sp;
}
//重载paintBorder方法 来画出我们想要的边框..
public void paintBorder(Graphics g){
Graphics2D g2 = (Graphics2D) g;
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
g2.setColor(new Color(150, 207, 254));
g2.drawRoundRect(0,-arrow.getHeight(),getWidth()-1,getHeight()+arrow.getHeight()-1,0,0);
}
};
return popup;
}
}
ok. 那么到这里 ComboBox这块已经end 但是似乎还有个问题存在 那就是createPopup 方法里的ScrollPane的滚动条还是有点丑.
so。.next 我们搞定 it.

1:继承 ScrollBar 并且 setUI();
2:继承 BasicScrollBarUI 我们来G出我们的效果.
paintThumb 绘制scrollbar里拖动的小box 我们先画个边框 and draw two Orange line.
paintTrack 绘制scrollbar里小box的轨迹.也就是那个啥(术语怎么说来着 拖拽滑块 ).
注意:我们首先将Graphics设置透明后 在去画面板 然后立刻把Graphics设置为不透明..
这样是为了能让我们把轨迹左边边界画出来...
createIncreaseButton draw down arrowButton 小心 千万不要use JButton button = new JButton();
should use BasicAr