package example;
import java.awt.BorderLayout;
import java.awt.Color;
import java.util.Vector;
import javax.swing.AbstractButton;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
public class main extends JFrame {
public main() {
JMenuBar menubar= new JMenuBar();//创建菜单栏
this.setJMenuBar(menubar);
JMenu menu=new JMenu("操作");//创建菜单
menubar.add(menu);
JMenuItem item1=new JMenuItem("导入资料");
JMenuItem item2=new JMenuItem("修改密码");
menu.add(item1);
menu.addSeparator();
menu.add(item2);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(400,400,500,500);
createTable();
setVisible(true);
}
public void createTable() {
String[] header= {"专辑名","歌名","收藏数","年代"};
String[][] cellDate=null;
DefaultTableModel tablemodel =new DefaultTableModel(cellDate,header) {
public boolean isCellEditable(int row, int column){
return false;
}
};
JTable jtable=new JTable (tablemodel); //把数据写入jtable
DefaultTableModel model=(DefaultTableModel)jtable.getModel();
int n=100;
model.setRowCount(n);
JScrollPane js=new JScrollPane(jtable); //把jtable放入滑板
JPanel jpanel=new JPanel(); //定义一个panel
jpanel.setBounds(40, 40, 680, 680); //设置panel的大小位置
jpanel.setBackground(Color.BLACK);
jpanel.setLayout(new BorderLayout());
jpanel.add(js); //把滑板放入panel
this.add(jpanel); //往主框架添加panel
}
public static void main(String[] args) {
new main();
}
}
原文地址:https://www.cnblogs.com/oldmemory/p/9521270.html