Detecting JSplitPane Divider Movement

青春壹個敷衍的年華 提交于 2019-12-12 10:29:54

问题


Is there a way to detect when a JSplitPane divider is moved? Is there a way to add a listener for divider movement?

JPanel panel1 = new JPanel();
JPanel panel2 = new JPanel();
JSplitPane sp = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, panel1, panel2);
// What do I put here to be notified if the divider in sp is moved?

回答1:


I think you're looking for addPropertyChangeListener from Container. Something like this...

sp.addPropertyChangeListener(JSplitPane.DIVIDER_LOCATION_PROPERTY, 
    new PropertyChangeListener() {
        @Override
        public void propertyChange(PropertyChangeEvent pce) {}
});



回答2:


Use

splitter.addPropertyChangeListener("dividerLocation", myListener);


来源:https://stackoverflow.com/questions/14468648/detecting-jsplitpane-divider-movement

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!