How to automatically update data in jtable (code implementation)

zhaozj2021-02-17  35

A good table control JTABLE is provided in Java, which we can easily populate data and display it, the following is the specific implementation of Java code:

/ / Define a JTABLE class

JTable TBL_PARAMS = New JTABLE ();

// Define the row data information container of the table. Vector Srcdata = new vector ();

// Initialize the column header of the table and related data information containers string [] columnName = {"Parameter name", "parameter value"}

// Set the column header Vector CNAME = New Vector (2); cName.Add (ColumnName [0]); cName.Add (ColumnName [1]);

DefaultTableModel Model = New DefaultTableModel (SDATA, CNAME); TBL_PARAMS.SETMODEL (MODEL);

// Fill data demo

Vector rowdata = new vector (2);

RowData.Add ("parameter name one");

RowData.Add ("Parameter Value One");

// Add the data to the container, which is added to JTABLE

Srcdata.add (rowdata);

......

// Finally refresh the JTABLE control

THIS.TBL_PARAMS.REPAINT (); this.tbl_params.Updateui ();

转载请注明原文地址:https://www.9cbs.com/read-29025.html

New Post(0)