JTable Control Add Delete Row __jtable

Source: Internet
Author: User
To add a row:

You cannot insert rows directly into JTable, and you need the help of JTable's TableModel code as follows:

Import Javax.swing.table.DefaultTableModel;

Import javax.swing.JTable;

。。。

JTable table = new JTable ();

DefaultTableModel model = (DefaultTableModel) Table.getmodel ();

Model.add (New string[]{"xxxxxxx", "Yyyyyy", "zzzzzzz"});

。。。
Delete Row:

Using the Model.removerow (index) method

Get the number of records:

You can use the GetRowCount () method of jtable directly, or you can use its model GetRowCount () method

Empty jtable:

Using the Model.setrowcount (0) method

To get JTable data:

It seems that the data can only be retrieved in vector form using the Getdatavector () method:

Import Java.util.Vector;
...

Vector data = ((DefaultTableModel) Tbinfo.getmodel ()). Getdatavector ();

The Vector object is also the vector object of the element data.

Get one row of data:

Vector rowdata =data.get (1);

Gets a data grid, a data in one row of data:

Vector rowdata =data.get (1);

String field = Rowdata.get (1);

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.