In this example we are going to see how to use Java Resize SplitPane
Java Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | import java.awt.BorderLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JSplitPane; public class Main { public static void main(String args[]) { String title = "Resize Split"; final JFrame vFrame = new JFrame(title); vFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JButton topButton = new JButton("Top"); JButton bottomButton = new JButton("Bottom"); final JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT); splitPane.setTopComponent(topButton); splitPane.setBottomComponent(bottomButton); ActionListener oneActionListener = new ActionListener() { public void actionPerformed(ActionEvent event) { splitPane.setResizeWeight(1.0); vFrame.setSize(300, 250); vFrame.validate(); } }; bottomButton.addActionListener(oneActionListener); ActionListener anotherActionListener = new ActionListener() { public void actionPerformed(ActionEvent event) { splitPane.setResizeWeight(0.5); vFrame.setSize(300, 250); vFrame.validate(); } }; topButton.addActionListener(anotherActionListener); vFrame.getContentPane().add(splitPane, BorderLayout.CENTER); vFrame.setSize(300, 150); vFrame.setVisible(true); } } |
Output: