软件编程
位置:首页>> 软件编程>> java编程>> Swing拆分窗格控件JSplitPane使用详解

Swing拆分窗格控件JSplitPane使用详解

作者:Damon-Da  发布时间:2022-11-14 21:13:48 

标签:Swing,JSplitPane

本文实例为大家分享了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();
}

}

效果图:

Swing拆分窗格控件JSplitPane使用详解

移动拆分线:

Swing拆分窗格控件JSplitPane使用详解

来源:http://blog.csdn.net/dada111111111/article/details/49853181

0
投稿

猜你喜欢

手机版 软件编程 asp之家 www.aspxhome.com