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 ();//Create menu bar
This.setjmenubar (menubar);
JMenu menu=new jmenu ("operation");//Create Menu
Menubar.add (menu);
JMenuItem item1=new JMenuItem ("Import material");
JMenuItem item2=new jmenuitem ("Change Password");
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= {"album name", "Song Name", "collection Number", "Age"};
String[][] Celldate=null;
DefaultTableModel TableModel =new DefaultTableModel (celldate,header) {
public boolean iscelleditable (int row, int column) {
return false;
}
};
JTable jtable=new JTable (TableModel); Write data to JTable
DefaultTableModel model= (DefaultTableModel) Jtable.getmodel ();
int n=100;
Model.setrowcount (n);
JScrollPane js=new JScrollPane (jtable); Put JTable into the skateboard
JPanel jpanel=new JPanel (); Define a panel jpanel.setbounds (40, 40, 680, 680); Set the size position of the panel
Jpanel.setbackground (Color.Black);
Jpanel.setlayout (New BorderLayout ());
Jpanel.add (JS); Put the skateboard into the panel
This.add (JPanel); Adding a panel to the main frame
}public static void Main (string[] args) {
New Main ();
}
}
Java Main Interface Table (set number of rows and read-only) (1) 2018.8.23