为了界面更cool,使用选项卡,代码演示:
package com.Swing;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTabbedPane;
public class JTablePanelTest extends JFrame{
/**
*
*/
private static final long serialVersionUID = 1L;
public JTablePanelTest(){
JTabbedPane jpt=new JTabbedPane(JTabbedPane.TOP);
JLabel[] lab=new JLabel[6];
Icon pic=null;
for(int i = 1;i<=5;i++){
pic=new ImageIcon("D:\\"+i+".jpg");
lab[i]=new JLabel();
lab[i].setIcon(pic);
String title="第"+i+"页";
jpt.add(title, lab[i]);
}
this.add(jpt);
}
public static void main(String[] args) {
JTablePanelTest j=new JTablePanelTest ();
j.setTitle("选项卡的使用");
j.setSize(500,500);
j.setLocationRelativeTo(null);
j.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
j.setVisible(true);
}
}