"Code Note" Java repeatedly see the implementation of the project (1)--jtable, TableModel use

Source: Internet
Author: User

  1. Javax.swing.table.TableModel and javax.swing.JTable
  2. JTable, TableModel is the Java inside the picture form package.
  3. TableModel: Provides table display data, table dimensions, table display data types, column headings, and other properties that the table needs to display
  4. JTable: Provides properties and actions for the table itself, such as table style, row height, background, row check properties, and so on
  5. JTable equivalent to Web pages, models, TableModel equivalent to servers, clothing.
  6. JTable and TableModel are interdependent relationships (equal to B/s mode)
  7. TableModel the role of the server, real data

  8. JTable to show something TableModel provide it, refresh once to request once

  9. 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

  10. Look at the project ideas repeatedly:
    1. Build a good form;
    2. Adding JTable Components
    3. Adding TableModel Components
  11. File directory:
  12. 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}

  13. 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

Related Article

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.