To write a large job in a database, it is inevitable that jtable is involved. Let's talk about some experiences using jtable: The jtable data source is an object called defaulttablemodel, which can be bound when jtable is created: defaulttablemodel model = new defaulttablemodel (); jtable table = new jtable (model); you can also use the setmodel function to set it later: Table. setmodel (model); All jtable element operations can be completed in defaulttablemodel, for example, adding a column element: model. addColumn ("column name"); this function also has an overload, that is, model. addColumn ("column name", object []); you can add an object array to the model as a column. defaulttablemodel also supports adding rows by row. There are two function overloading: addrow (object []), addrow (vector); the function automatically maps the elements in the array or vector to the column to modify the element in the Table: setvalueat (Object A, int row, int column ); delete a row: removerow (INT row). This job has encountered several problems. The solution may be: 1. the column name cannot be displayed. If jtable is directly added to a iner, its column name will not be displayed. You must add a jscrollpane containing jtable to the container to correctly display the column name usage: defaulttablemodel model = new defaulttablemodel (); jtable table = new jtable (model); this. getcontentpane (). add (New jscrollpane (table); this is a jframe or other iner, such as jpanel 2. when you want to use this area to display the content of another table, the added column names cannot be deleted. I tried to find the removeall function in defaulttablemodel, but failed. Finally, I still used a helpless method... new defaulttablemodel, modify the jtable model binding example: Table. removeall (); defaulttablemodel model = new defaulttablemodel ();
Table. setmodel (model );
Model. AddColumn ("room number ");
Model. AddColumn ("room IP Address ");
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