Detecting JSplitPane Divider Movement
Asked Answered
B

2

19

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?
Beekeeper answered 22/1, 2013 at 21:50 Comment(0)
G
32

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) {}
});
Groundling answered 22/1, 2013 at 21:57 Comment(0)
D
6

Use

splitter.addPropertyChangeListener("dividerLocation", myListener);
Deaminate answered 22/1, 2013 at 22:1 Comment(1)
better use the DIVIDER_LOCATION_PROPERTY constant instead of the String itselfTrochelminth

© 2022 - 2024 — McMap. All rights reserved.