Eac patent java

JTableHeader JTableHeader 1 = jtable 1 . gettableheader();

//★ What is this?

A table consists of two parts: column headings and column objects. The column header object is obtained by using the getTableHeader () method provided by JTable.

JB init(); //★ What is this?

This is the private void jbinit () throwsexception method written below. As far as I know, the function name means (JTable initial: table initialization), which is nothing more than setting the properties of the table, such as resizing and scrolling, and finally adding the table to the frame. In fact, this is very tiring, and you can use the JScrollPane class to scroll.

Namely:

JScrollPane sl pane = new JScrollPane(jtable 1,JScrollPane。 As needed. Horizontal _ scroll bar _ always);

this.getContentPane()。 add(slPane,BorderLayout。 Center); //If it is a border layout manager. . .

The realization of PS: JTable can adopt MVC architecture, namely model, view and control structure. There is an interface TableModel in java to realize data modeling of tables. Its abstract implementation class (most methods are implemented, but only three methods are not) is AbstractTableModel, which can be inherited. By implementing three methods, a JTable can be constructed, such as

JTable table 1 = new JTable(new abstract table model(){

public int getColumnCount() {...}

public int getRowCount() {...}

Public object getValueAt(int rowIndex, int columnIndex) {...}

});

Three of these methods must be implemented so that a table can have a data model. When the data changes, just call table1.validate (); Function to change the displayed results. See page 323, Volume II of java2 Core Technology for details.