Reputation: 1042
Status: I want to display 2 JPanels which contain images using a JSplitPane (one image at the top, one image at the bottom)
When I move the divider of the pane, I want both panels to resize accordingly. (that the images take up the maximum possible space)
The Problem: I'm using a PropertyChangeListener to track the change of position of the divider, but the event seems to be fired before the actual "repaint?" of the window has taken place
What i've tried: - repainting the component before reading the size
Minimum working example:
public class Main {
public static void main(String argv[]) {
MyFrame f = new MyFrame();
}
}
class MyFrame extends JFrame {
/**
*
*/
private static final long serialVersionUID = 1L;
JPanel anyPanel, anyPanel2;
JSplitPane p;
public MyFrame() {
PropertyChangeListener resizeHandler = new PropertyChangeListener() {
@Override
public void propertyChange(PropertyChangeEvent evt) {
System.out.println(anyPanel.getHeight());
}
};
anyPanel = new JPanel();
anyPanel2 = new JPanel();
p = new JSplitPane(JSplitPane.VERTICAL_SPLIT, anyPanel, anyPanel2);
p.addPropertyChangeListener(JSplitPane.DIVIDER_LOCATION_PROPERTY, resizeHandler);
getContentPane().add(p);
this.add(p);
this.pack();
this.setVisible(true);
}
}
Upvotes: 1
Views: 2140