java主界面表格(設置行數和只讀)(1)2018.8.23
阿新 • • 發佈:2018-08-23
item javax etl border ati int jframe col cell 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();
}
}
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();
}
}
java主界面表格(設置行數和只讀)(1)2018.8.23