swing split window control JSplitPane usage details

  • 2020-11-30 08:22:21
  • OfStack

This article shares the use method of JSplitPane for your reference. The specific content is as follows

swing split window control JSplitPane, used to split the window into two parts.

2, each window after the split can only put 1 control, want to have more than one control, you can be in the above one JPane panel, so you can have more than one control. swing Split window control JSplitPane, which is used to split a window into two parts. JSplitPane provides two constants that allow you to set whether you want to split vertically or horizontally. The two constants are HORIZONTAL_SPIT and VERTICAL_SPLIT

3. Usage:

, setDividerSize(int size) set the size of the split bar.

, getDividerSize() to get the size of the partition bar.

, setDividerLocation(int size) set the position of the split bar according to the percentage.

, getOrientation get the direction.

4. Construction method

JSplitPane(): Create a new JSplitPane with two default buttons arranged horizontally and without Continuous Layout functionality.

JSplitPane(int newOrientation): Creates a specified horizontal or vertical cut JSplitPane, but does not have Continuous Layout functionality.

JSplitPnae(int newOrientation,boolean newContinuousLayout): Creates an JSplitPane that specifies horizontal or vertical cutting and specifies whether it has Continuous Layout functionality.

JSplitPane(int newOrientation,boolean newContinuousLayout,Component
newLeftComponent,Component newRightComponent): Create a specified horizontal or vertical cut JSplitPane, and specify the components to be displayed in the display area, and set whether Continuous Layout functions or not.

JSplitPane(int newOrientation,COmponent newLeftComponent,COmponent newRightComponent):
Set up an JSplitPane with a specified horizontal or vertical cut, and specify the components to be displayed in the display area, but without Continuous Layout functionality.

Continuous Layout above refers to whether components in the window dynamically change size as you drag and drop the divider on the cut panel. newContinuousLayout is an boolean value. If set to true, the component size will change 1 with the drag of the separator. If set to false, the component size is determined when the delimiter stops changing. You can also set up this project using the setContinuousLayout() method in JSplitPane.

5, the instance,


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 exit automatically after closing  
  this.setSize(800,600);// Sets the default size of the form  
  this.setExtendedState(JFrame.MAXIMIZED_BOTH);// Set form state to screen maximum, i.e. full screen size.  
  this.setVisible(true);// According to the form  
  this.jSplitPane1.setDividerLocation(0.7);// Set the left and right proportions of the split panel ( That's when it takes effect setVisible(true) It wouldn't have worked before. ) 
  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); 

 } 


} 

Related articles: