布局:
package com.text01;
import javax.swing.*;
public class Demo8_8 extends JFrame {
JSplitPane jsp;
JList jList;
JLabel jl1;
public static void main(String[] args) {
// TODO 自动生成的方法存根
Demo8_8 demo8_8 = new Demo8_8();
}
public Demo8_8(){
String[] words = {"boy", "girl", "bird"};
jList = new JList(words);
jl1 = new JLabel(new ImageIcon("images/2.jpg"));
// 创建可拆分窗格
jsp = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, jList, jl1);
// 设置图片大小可以变化
jsp.setOneTouchExpandable(true);
this.add(jsp);
this.setSize(400, 300);
this.setLocation(200, 200);
this.setVisible(true);
}
}
运行效果图:
添加左上角图标以及设置布局:
代码:
package com.text01;
import java.awt.BorderLayout;
import javax.swing.*;
public class Demo8_9 extends JFrame{
JScrollPane jsp = null;
JTextArea jta = null;
JPanel jp1 = null;
JComboBox jcb = null;
JTextField jtf = null;
JButton jb = null;
public static void main(String[] args) {
// TODO 自动生成的方法存根
Demo8_9 demo8_9 = new Demo8_9();
}
public Demo8_9(){
jta = new JTextArea();
jsp = new JScrollPane(jta);
jp1 = new JPanel();
String[] chatter = {"bushi", "ladeng"};
jcb = new JComboBox(chatter);
jtf = new JTextField(10);
jb = new JButton("Send");
// 设置布局
// 添加主键
jp1.add(jcb);
jp1.add(jtf);
jp1.add(jb);
this.add(jsp);
this.add(jp1, BorderLayout.SOUTH);
// 设置窗体属性
this.setIconImage((new ImageIcon("images/3.jpg")).getImage());
this.setSize(300, 200);
this.setTitle("Dikea Author");
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);
}
}
运行效果图: