有没有办法检测 JSplitPane 分隔线何时移动?有没有办法为分隔线运动添加监听器?
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?
有没有办法检测 JSplitPane 分隔线何时移动?有没有办法为分隔线运动添加监听器?
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?
我认为您正在寻找addPropertyChangeListener from Container。像这样的东西...
sp.addPropertyChangeListener(JSplitPane.DIVIDER_LOCATION_PROPERTY,
new PropertyChangeListener() {
@Override
public void propertyChange(PropertyChangeEvent pce) {}
});
采用
splitter.addPropertyChangeListener("dividerLocation", myListener);