java主界面表格(设置行数和只读)(1)2018.8.23
2021-07-19 14:05
标签:this 界面 [] string menuitem ane false bsp cell java主界面表格(设置行数和只读)(1)2018.8.23 标签:this 界面 [] string menuitem ane false bsp cell 原文地址:https://www.cnblogs.com/oldmemory/p/9521270.html
import java.awt.Color;
import java.util.Vector;
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 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.setBackground(Color.BLACK);
jpanel.setLayout(new BorderLayout());
jpanel.add(js); //把滑板放入panel
this.add(jpanel); //往主框架添加panel
new main();
}
}
上一篇:linux下多线程编程
下一篇:python第一课
文章标题:java主界面表格(设置行数和只读)(1)2018.8.23
文章链接:http://soscw.com/index.php/essay/106320.html