java中JSplitPane放在JPanel中的例子

这是一个关于java中JSplitPane放在JPanel中的例子,在网上找了很多列子都是直接放在JFrame中的,因为才刚开始学习java,所以对于很多都不太了解,...所以...当发现一些问题的时候比较兴奋...本例子就是关于JSplitPane放在JPanel中不能显示全部的问题,关键在于JPanel和JFrame的默认布局管理器不一样的原因...  希望有一样对java感兴趣的同志一起相互学习...我的主页http://etwo.javaeye.com/我的QQ:369342286

package net.etwo.jsplitpane.test;

import java.awt.BorderLayout;
import java.awt.Color;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JSplitPane;
import javax.swing.border.LineBorder;

public class TestJSplitPane {

private JFrame jframeMain = new JFrame();
private JPanel jpanelMain = new JPanel();

// 用于分割两个(只能两个)component
private JSplitPane jsplitPaneTestOne = new JSplitPane();
// 上下
private JSplitPane jsplitPaneTextTwo = new JSplitPane(
JSplitPane.VERTICAL_SPLIT);

public TestJSplitPane() {
// TODO Auto-generated constructor stub
// 设置分隔条的位置
jsplitPaneTestOne.setDividerLocation(40);
// 将组件分配到分隔符的左边
jsplitPaneTestOne.setLeftComponent(new JLabel("左边"));

jsplitPaneTextTwo.setDividerLocation(80);
//设置分隔条的大小
jsplitPaneTextTwo.setDividerSize(20);
//快速展开/折叠分隔条(默认为false)
jsplitPaneTextTwo.setOneTouchExpandable(true);
jsplitPaneTextTwo.setLeftComponent(new JLabel("上面"));
jsplitPaneTextTwo.setRightComponent(new JLabel("下面"));


// 将组件分配到分隔符的右边
jsplitPaneTestOne.setRightComponent(jsplitPaneTextTwo);

jpanelMain.setBorder(new LineBorder(Color.red));

//设置jpanelMain的布局管理
jpanelMain.setLayout(new BorderLayout());

jpanelMain.add(jsplitPaneTestOne);
jframeMain.add(jpanelMain);

jframeMain.setTitle("分割面板");
jframeMain.setSize(500, 600);
jframeMain.setLocationRelativeTo(null);
jframeMain.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jframeMain.setVisible(true);
}

public static void main(String[] args) {
new TestJSplitPane();
}
}

 

 

你可能感兴趣的:(java,JPanel,swing,etwojavaeye,jsplitpane)