This article shares the usage method of JSplitPane for your reference. The specific content is as follows
1. Swing split window control JSplitPane is used to split the window into two parts.
2. Each window after the split can only have one control. If you want multiple controls, you can have a JPane panel on top, so that multiple controls can be placed. swing split window control JSplitPane is used to split the window into two parts. JSplitPane provides two constants for you to set whether to split vertically or horizontally. These two constants are: HORIZONTAL_SPIT, VERTICAL_SPLIT
3. How to use:
①, setDividerSize(int size) sets the size of the segmentation bar.
②. getDividerSize() to obtain the size of the segmented bar.
③, setDividerLocation(int size) Set the position of the segmented bar according to the percentage.
④, getOrientation to obtain direction.
4. Construction method
JSplitPane(): Create a new JSplitPane, which contains two default buttons, arranged horizontally, and does not have the Continuous Layout function.
JSplitPane(int newOrientation): Creates a specified horizontal or vertical cutting of JSplitPane, but does not have the Continuous Layout function.
JSplitPnae(int newOrientation,boolean newContinuousLayout): Create a JSplitPane that specifies horizontal or vertical cutting, and specify whether it has the Continuous Layout function.
JSplitPane(int newOrientation,boolean newContinuousLayout,Component
newLeftComponent,Component newRightComponent): Create a JSplitPane that specifies the horizontal or vertical direction to be cut, and specify the components to be displayed in the display area, and set whether to have the Continuous Layout function.
JSplitPane(int newOrientation,COMponent newLeftComponent,COMponent newRightComponent):
Create a JSplitPane that specifies horizontal or vertical cutting, and specifies the components to be displayed in the display area, but does not have the Continuous Layout function.
The Continuous Layout mentioned above means whether the components in the window will dynamically change the size as the divider is dragged by the partition. newContinuousLayout is a boolean value. If set to true, the component size will change with the drag of the divider; if set to false, the component size will be determined only when the divider stops changing. You can also set this project using the setContinuousLayout() method in JSplitPane.
5. Example
package swing; import java.awt.event.ComponentAdapter; import java.awt.event.ComponentEvent; import javax.swing.JFrame; import javax.swing.JSplitPane; import javax.swing.JPanel; public class MainFrame extends JFrame { /** * */ JSplitPane jSplitPane1 = new JSplitPane(); JPanel jPanel1 = new JPanel(); JPanel jPanel2 = new JPanel(); private static final long serialVersionUID = 1L; public static void main(String[] args){ new MainFrame(); } public void myinit(){ this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//Set the form to automatically exit the process after closing this.setSize(800,600);//Set the default size of the form this.setExtendedState(JFrame.MAXIMIZED_BOTH);//Set the form status to screen maximization, that is, the full screen size. this.setVisible(true);//Show the form this.jSplitPane1.setDividerLocation(0.7);//Set the left and right ratio of the split panel (it will take effect at this time. If placed in setVisible(true) data, it will not be effective before it is placed.) this.addComponentListener(new ComponentAdapter() { public void componentResized(ComponentEvent e) { jSplitPane1.setDividerLocation(0.7); } }); } public MainFrame() { try { jbInit(); myinit(); } catch (Exception ex) { ex.printStackTrace(); } } private void jbInit() throws Exception { this.getContentPane().add(jSplitPane1, java.awt.BorderLayout.CENTER); jSplitPane1.add(jPanel1, JSplitPane.LEFT); jSplitPane1.add(jPanel2, JSplitPane.RIGHT); jSplitPane1.setEnabled(false); jSplitPane1.setOneTouchExpandable(true); } } The above is all the content of this article. I hope it will be helpful to everyone's learning and I hope everyone will support Wulin.com more.