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

这篇文章主要为大家详细介绍了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使用详解的详细内容,更多请关注0133技术站其它相关文章!

赞(0) 打赏
未经允许不得转载:0133技术站首页 » Java