JAVA进阶5.11——拆分窗口

import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JSplitPane;

public class Test extends JFrame{
	JSplitPane chaiFen;//声明拆分模块。
	JList lieBiao; //声明左侧列表。
	JLabel label;//声明标签。

	public static void main(String[] args) {
		Test t1 = new Test();
	}

	Test() {
		String[] fenQu = { "软件开发", "游戏开发", "平面设计", "动画制作", "室内设计" };//创建数组。
		lieBiao = new JList(fenQu); //数组赋值给列表

		label = new JLabel(new ImageIcon("image/1.png"));//标签插入图片,图片的位置在Test工程下的image文件夹(自己创建)中。
		chaiFen = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, lieBiao, label);//左右拆分,左侧列表,右侧标签。

		chaiFen.setOneTouchExpandable(true);//拆分模块可以用鼠标调整具体位置。

		this.add(chaiFen);//主窗口添加拆分模块。
		this.setTitle("计算机学科分类");//设置标题。
		this.setSize(640, 480);
		this.setLocation(300, 280);
		this.setResizable(false);
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		this.setVisible(true);
	}

}

你可能感兴趣的:(JAVA)