Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detecting JSplitPane Divider Movement

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?
like image 486
Adude11 Avatar asked Jan 22 '13 21:01

Adude11


2 Answers

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) {}
});
like image 179
Anthony Neace Avatar answered Nov 04 '22 23:11

Anthony Neace


Use

splitter.addPropertyChangeListener("dividerLocation", myListener);
like image 45
Sergiy Medvynskyy Avatar answered Nov 04 '22 22:11

Sergiy Medvynskyy