オブジェクト[][] data = {{1,2,3},{2,3,4},{4,5,6},{7,8,9}}; 文字列[] title= {"Column1", "Column2", "Column3"}; JTable の例JTable = 新しいJTable(データ、列名)}; |
System.out.println(exampleJTable.getValueAt(2, 2)); |
TableModel byDefault = exampleJTable.getModel(); System.out.println(exampleJTable.getValueAt(2, 2).toString()); |
class Model extends AbstractTableModel{このコードは、テンプレートを table
private Object[][] data;
private String[] title;
public Model(Object[][] data, String[] title){
this.data = data;
this.title = タイトル;
}
/**
* カラムタイトルとインデックスを返す
*/
public String getColumnName(int col) {
return this.title[col];
}
/**
* 列数を返します
*/
public int getColumnCount() {
return this.title.length;
}
/**
* 行数を返します
*/
public int getRowCount() {
return this.data.length;
}
/**
* 行と列の交点にあるオブジェクトを返します
*/
public Object getValueAt(int row, int col) {
return this.data[row][col];
}
/**
* 行と列の交点でオブジェクトを変更
*/
public void setValueAt(Object value, int row, int col) {
this.data[row][col] = value;
}
}
//JTable JTableテーブル= new JTable(); //テンプレートの作成 Model =new Model(data, title); //テンプレートをJTable table.setModel(model); |
Please disable your ad blocker and refresh the window to use this website.