Created
July 27, 2013 16:14
-
-
Save fanjavaid/6095314 to your computer and use it in GitHub Desktop.
Membuat TableModel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* To change this template, choose Tools | Templates | |
* and open the template in the editor. | |
*/ | |
package com.fandi.barang; | |
import java.util.ArrayList; | |
import java.util.List; | |
import javax.swing.table.AbstractTableModel; | |
/** | |
* | |
* @author fandy | |
*/ | |
public class TableModel extends AbstractTableModel { | |
private List<Barang> listBarang; | |
public TableModel() { | |
listBarang = new ArrayList<>(0); | |
fireTableDataChanged(); | |
} | |
public void setBarang(List<Barang> listBarang) { | |
this.listBarang = listBarang; | |
} | |
@Override | |
public int getRowCount() { | |
return listBarang.size(); | |
} | |
@Override | |
public int getColumnCount() { | |
return 3; | |
} | |
@Override | |
public Object getValueAt(int rowIndex, int columnIndex) { | |
switch(columnIndex) { | |
case 0 : | |
return listBarang.get(rowIndex).getKode(); | |
case 1 : | |
return listBarang.get(rowIndex).getNama(); | |
case 2 : | |
return listBarang.get(rowIndex).getQty(); | |
default : | |
return null; | |
} | |
} | |
public String getColumnName(int columnIndex) { | |
switch(columnIndex) { | |
case 0 : | |
return "Kode"; | |
case 1 : | |
return "Nama"; | |
case 2 : | |
return "QTY"; | |
default : | |
return null; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment