extends AbstractTableModel : AbstractTableModel « javax.swing.table « Java by API






extends AbstractTableModel

import java.awt.BorderLayout;

import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.AbstractTableModel;
import javax.swing.table.TableModel;

public class MainClass {

  public static void main(final String args[]) {
    final Object rows[][] = { { "one", "1" }, { "two", "2" },
        { "three", "3" } };
    final String headers[] = { "English", "Digit" };
    
    TableModel fixedColumnModel = new AbstractTableModel() {
      public int getColumnCount() {
        return 2;
      }
      public String getColumnName(int column) {
        return headers[column];
      }
      public int getRowCount() {
        return 3;
      }
      public Object getValueAt(int row, int column) {
        return rows[row][column];
      }
    };
    
    
    
    JFrame frame = new JFrame("Scrollless Table");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JTable table = new JTable(fixedColumnModel);
    
    table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
    
    frame.add(new JScrollPane(table), BorderLayout.CENTER);
    frame.setSize(300, 150);
    frame.setVisible(true);
  }
}

           
       








Related examples in the same category

1.extends AbstractTableModel (read database table to a JTable)
2.extends AbstractTableModel (Custom class type)
3.AbstractTableModel: fireTableRowsUpdated(int firstRow, int lastRow)