拆分窗格



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

/**
 * 
 * 词霸
 * JSplitPane 拆分窗格  
 *
 */
public class Test3 {
 public static void main(String args[]){
  new MyFrame2();
 }
}

class MyFrame2 extends JFrame{
 
 JSplitPane jsp=null;
 JList jlist=null;
 JLabel jl1=null; 
 public MyFrame2(){
  //创建组件
  String []words = {"boy","girl","hi"};
  jlist = new JList(words);
  
  jl1 = new JLabel(new ImageIcon("images/1.png"));
  //拆分窗格
  jsp = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,jlist,jl1);
  
  //JList可以伸缩变化
  jsp.setOneTouchExpandable(true);
  //设置布局管理器
  
  //添加
  this.add(jsp);
  
  this.setBounds(400,400,400,300);
  this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  this.setVisible(true);
 }
}


你可能感兴趣的:(JavaSE,GUI)