Java Main Interface Table (set number of rows and read-only) (1) 2018.8.23

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.