我想在JSplitPane
中获取divider组件。我想将MouseListener
附加到它。
如何获取JSplitPane
的分隔符组件?
谢谢!
答案 0 :(得分:3)
我想将鼠标监听器附加到它上面。
为什么需要MouseListener(如果我们知道实际需求,可能会有更好的解决方案)?
我想在JSplitPane中获取divider组件。
你从UI获得分隔符:
BasicSplitPaneUI ui = (BasicSplitPaneUI)splitPane.getUI();
BasicSplitPaneDivider divider = ui.getDivider();
答案 1 :(得分:1)
试试这个 -
最初:
JSplitPane pane = new JSplitPane(JSPlitPane.HORIZONTAL_SPLIT, panelOne, panelTwo);
pane.addPropertyChangeListener(JSplitPane.DIVIDER_LOCATION_PROPERTY, new PropertyChangeListener() {
@Override
public void propertyChange(PropertyChangeEvent propertyChangeEvent) {
// some processing here
}
});
更新:
JSplitPane pane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, panelOne, panelTwo);
BasicSplitPaneUI basicSplitPaneUI = (BasicSplitPaneUI) pane.getUI();
BasicSplitPaneDivider basicSplitPaneDivider = basicSplitPaneUI.getDivider();
basicSplitPaneDivider.addMouseMotionListener(new MouseMotionAdapter() {
@Override
public void mouseDragged(MouseEvent e) {
// some processing here
}
});