For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!
Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.
import java.awt.*; import java.beans.*; import java.awt.event.*; import javax.swing.*; public class SplitPaneResizing extends JFrame implements PropertyChangeListener { JSplitPane left; JSplitPane right; public SplitPaneResizing() { JSplitPane main = new JSplitPane(); getContentPane().add( main ); left = new JSplitPane(JSplitPane.VERTICAL_SPLIT); right = new JSplitPane(JSplitPane.VERTICAL_SPLIT); main.setLeftComponent( left ); main.setRightComponent( right ); // left.setTopComponent( createPanel(Color.RED) ); left.setBottomComponent( createPanel(Color.GREEN) ); right.setTopComponent( createPanel(Color.BLUE) ); right.setBottomComponent( createPanel(Color.WHITE) ); // left.addPropertyChangeListener( this ); right.addPropertyChangeListener( this ); } private JPanel createPanel(Color background) { JPanel panel = new JPanel(); panel.setPreferredSize( new Dimension(200, 100) ); panel.setBackground( background ); return panel; } public void propertyChange(PropertyChangeEvent e) { if ("dividerLocation".equals(e.getPropertyName())) { Object source = e.getSource(); JSplitPane target = (source.equals(left)) ? right : left; int location = ((Integer)e.getNewValue()).intValue(); if (location != target.getDividerLocation()) target.setDividerLocation( location ); } } public static void main(String[] args) { SplitPaneResizing frame = new SplitPaneResizing(); frame.setDefaultCloseOperation( EXIT_ON_CLOSE ); frame.pack(); frame.setLocationRelativeTo( null ); frame.setVisible(true); } }
left.setContinuousLayout(true); right.setContinuousLayout(true);