- Javax.swing.table.TableModel and javax.swing.JTable
- JTable, TableModel is the Java inside the picture form package.
- TableModel: Provides table display data, table dimensions, table display data types, column headings, and other properties that the table needs to display
- JTable: Provides properties and actions for the table itself, such as table style, row height, background, row check properties, and so on
- JTable equivalent to Web pages, models, TableModel equivalent to servers, clothing.
- JTable and TableModel are interdependent relationships (equal to B/s mode)
TableModel the role of the server, real data
JTable to show something TableModel provide it, refresh once to request once
Deal with the elimination of logic (algorithm implementation):
1) The same image can be eliminated
2) No obstructions can be eliminated in the same row or column
3) A turning point to eliminate
4) Two inflection points to eliminate
- Look at the project ideas repeatedly:
- Build a good form;
- Adding JTable Components
- Adding TableModel Components
- File directory:
- Tbaleframe.java
1 PackageCom.edp.impl;2 3 4 Importjava.awt.FlowLayout;5 6 ImportJavax.swing.JFrame;7 Importjavax.swing.JTable;8 9 /**Ten * One * @authorAdministrator A * - */ -@SuppressWarnings ("Serial") the Public classTableFrameextendsjframe{ - Public Static voidMain (string[] args) { - Newtableframe (). Initframe (); - } + - Private voidInitframe () { + This. SetSize (800,600); A This. setdefaultcloseoperation (3); at This. setlayout (NewFlowLayout ()); - //setting a form cannot change size - This. setresizable (false); - This. Setlocationrelativeto (NULL); - -Mytablemodel MTM =NewMytablemodel (); inJTable table =NewJTable (MTM); - This. Add (table); to This. setvisible (true); + - } the}
- Mytablemodel.java
1 PackageCom.edp.impl;2 3 ImportJavax.swing.event.TableModelListener;4 ImportJavax.swing.table.TableModel;5 6 Public classMytablemodelImplementsTableModel {7 //Get column type8 PublicClass<?> getColumnClass (intcolumnindex) {9 returnString.class;Ten } One //get total number of rows A Public intGetRowCount () { - return0; - } the //get total number of columns - Public intgetColumnCount () { - return0; - } + //get table column names - PublicString getColumnName (intcolumnindex) { + return NULL; A } at //Set cell data - Public voidsetValueAt (Object Avalue,intRowIndex,intcolumnindex) { - } - //Get Cell data - PublicObject getValueAt (intRowIndex,intcolumnindex) { - return0; in } - //whether the cell is edited to Public BooleanisCellEditable (intRowIndex,intcolumnindex) { + return true; - } the Public voidRemovetablemodellistener (Tablemodellistener l) {} * Public voidAddtablemodellistener (Tablemodellistener l) {} $}
"Code Note" Java repeatedly see the implementation of the project (1)--jtable, TableModel use