上网找了下想改变下分隔条的颜色,或者设置自己的图片,百度,google基本找不到.
于是,没办法,只能花学时间去搞搞.刚好也可以复习一下UI.
步骤一:先找到JSplitPane
找到它的setUI方法
/** * Sets the L&F object that renders this component. * * @param ui the <code>SplitPaneUI</code> L&F object * @see UIDefaults#getUI * @beaninfo * bound: true * hidden: true * attribute: visualUpdate true * description: The UI object that implements the Component's LookAndFeel. */ public void setUI(SplitPaneUI ui) { if ((SplitPaneUI)this.ui != ui) { super.setUI(ui); revalidate(); } }
这是一个设置JSplitPane UI的方法.
于是我们可以重写SplitPaneUI,但这时我们发现它是一个抽象的方法,所以想必它有很多实现类.我们可能找它的实现类.里面有各种UI方法的子类.分别用来设置各种外观.
下一步:
找到它的子类BasicSplitPaneUI,想想,JSplitPane想重写中间的拖动条
我们可以先看下BasicSplitPaneUI的实现代码,先看下它的变量
/** * The divider used for non-continuous layout is added to the split pane * with this object. */ protected static final String NON_CONTINUOUS_DIVIDER = "nonContinuousDivider"; /** * How far (relative) the divider does move when it is moved around by * the cursor keys on the keyboard. */ protected static int KEYBOARD_DIVIDER_MOVE_OFFSET = 3; /** * JSplitPane instance this instance is providing * the look and feel for. */ protected JSplitPane splitPane; /** * LayoutManager that is created and placed into the split pane. */ protected BasicHorizontalLayoutManager layoutManager; /** * Instance of the divider for this JSplitPane. */ protected BasicSplitPaneDivider divider; /** * Instance of the PropertyChangeListener for this JSplitPane. */ protected PropertyChangeListener propertyChangeListener; /** * Instance of the FocusListener for this JSplitPane. */ protected FocusListener focusListener; private Handler handler;
从上面容易看出divider就是分隔条,
同时
public class BasicSplitPaneDivider extends Container implements PropertyChangeListener
可以看出它也是个组件,而且在BasicSplitPaneUI中它是个保护成员变量,所以我们想想,重新写它的paint方法,在里面我们可以设置颜色或者图片等.讲得太多变啰嗦了,呵呵,有兴趣的自己看看我的附件代码吧.