Swing拆分窗格控件JSplitPane使用详解
更新:HHH   时间:2023-1-7


本文实例为大家分享了Swing拆分窗格控件JSplitPane的使用方法,供大家参考,具体内容如下

package day1115;
import javax.swing.*;
import java.awt.Color;
public class Test3 {
public static void main(String[] args)
{
  JFrame frame=new JFrame ("test window ");
  frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  frame.setVisible(true);
  JPanel j1= new JPanel();
  JPanel j2= new JPanel();
  j1.setBackground(Color.red);
  j2.setBackground(Color.green);
  JSplitPane splitPane=new JSplitPane();//创建一个分割容器类
  splitPane.setOneTouchExpandable(true);//让分割线显示出箭头
  splitPane.setContinuousLayout(true);//操作箭头,重绘图形
  splitPane.setOrientation(JSplitPane.HORIZONTAL_SPLIT);//设置分割线方向 纵向分布
  splitPane.setLeftComponent(j1);//设置左边的组件
  splitPane.setRightComponent(j2);//设置右边的组件
  splitPane.setDividerSize(1);//设置分割线的大小
  splitPane.setDividerLocation(50);//设置分割线位于中央

  frame.setContentPane(splitPane);
  //frame.pack(),这个函数的作用就是根据窗口里面的布局及组件的preferedSize来确定frame的最佳大小。
  frame.pack();
}

}


效果图:

移动拆分线:

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持天达云。

返回编程语言教程...