Creating a JTable Component

The following creates a table that uses an efficient underlying storage implementation. Although cell values can be changed, rows and columns cannot be added or deleted.
// Create with initial data Object[][] cellData = { {"row1-col1", "row1-col2"}, {"row2-col1", "row2-col2"}}; String[] columnNames = {"col1", "col2"}; JTable table = new JTable(cellData, columnNames);
The following creates tables that allow rows and columns to be added or deleted:
// Create a table with empty cells int rows = 10; int cols = 5; table = new JTable(rows, cols); // Create a table with initial data Vector rowData = new Vector(); for (int i=0; i<cellData.length; i++) { Vector colData = new Vector(Arrays.asList(cellData[i])); rowData.add(colData); } Vector columnNamesV = new Vector(Arrays.asList(columnNames)); table = new JTable(rowData, columnNamesV);

Comments

11 Feb 2010 - 12:24am by Passionate (not verified)

Hello I dont understand,Firstly we are declaring Jtable using JtableConstructor and tell me how to add values to that
Values should be in dynamic

11 Feb 2010 - 12:26am by Passionate (not verified)

Good Now I Understand How to Declare..Explain me the Secondpart..

Post a comment

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters shown in the image. Ignore spaces and be careful about upper and lower case.