.: Java :. Membuat Tabel dengan AWT

package JFrame;

import java.awt.BorderLayout;
import java.io.IOException;
import java.util.Vector;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

/**
*
* @author MSI
*/
public class contoh_tabel {
public static void main(String[] args) throws IOException {
Object rows[][] = { { “Dimas Santoso”, “Laki – Laki”, “Gresik”, “20”, ” Gatal – Gatal”, “Super VIP”, “6250000” },
{ “Aang Kunaifi”, “Laki – Laki”, “Banyuwangi”, “20”,” Amandel”, “Biasa”, “690000”}, };
Object headers[] = { “Nama”, “Jenis Kelamin”, “Alamat”, “Usia”,”Jenis Penyakit”,”Kelas”,” Jumlah Pembayaran” };
JFrame frame = new JFrame(“Hasil”);
class CustomTableModel extends DefaultTableModel {
public CustomTableModel(Object rowData[][], Object columnNames[]) {
super(rowData, columnNames);
}

public Class getColumnClass(int col) {
Vector v = (Vector) dataVector.elementAt(0);
return v.elementAt(col).getClass();
}

public boolean isCellEditable(int row, int col) {
return true;
}
}
JTable table = new JTable(new DefaultTableModel(rows, headers));
JScrollPane scrollPane = new JScrollPane(table);
frame.getContentPane().add(scrollPane, BorderLayout.CENTER);
frame.setSize(1000, 200);
frame.setVisible(true);
frame.setVisible(true);
}
}

Berikut hasil outputnya :

array

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s