我想在JSplitPane
中获得除法器组件。我想把MouseListener
附在上面。
如何获取JSplitPane
的除法器组件?
谢谢!
我想把鼠标监听器连接到它上。
为什么您需要MouseListener(如果我们知道实际需求,可能会有更好的解决方案)?
我想在JSplitPane中获得分隔器组件。
您可以从UI中获得分隔符:
BasicSplitPaneUI ui = (BasicSplitPaneUI)splitPane.getUI();
BasicSplitPaneDivider divider = ui.getDivider();
试试这个-
最初:
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
}
});