package com.java.myapp;
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
public class MyForm extends JFrame {
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
MyForm frame = new MyForm();
frame.setVisible(true);
}
});
}
/**
* Create the frame.
*/
public MyForm() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 580, 242);
setTitle("ThaiCreate.Com Java GUI Tutorial");
getContentPane().setLayout(null);
// ScrollPane for Table
JScrollPane scrollPane = new JScrollPane();
scrollPane.setBounds(33, 41, 494, 90);
getContentPane().add(scrollPane);
// Table
final JTable table = new JTable()
{
public boolean isCellEditable(int rowIndex, int vColIndex) {
return false;
}
};
scrollPane.setViewportView(table);
// Model for Table
DefaultTableModel model = new DefaultTableModel() {
public Class<?> getColumnClass(int column) {
switch (column) {
case 0:
return String.class;
case 1:
return String.class;
case 2:
return String.class;
case 3:
return String.class;
case 4:
return String.class;
case 5:
return String.class;
default:
return String.class;
}
}
public boolean isCellEditable(int rowIndex, int mColIndex) {
return false;
}
};
table.setModel(model);
model.addColumn("CustomerID");
model.addColumn("Name");
model.addColumn("Email");
model.addColumn("CountryCode");
model.addColumn("Budget");
model.addColumn("Used");
// Data Row
for (int i = 0; i <= 10; i++) {
model.addRow(new Object[0]);
model.setValueAt("Row"+ (i+1), i, 0);
model.setValueAt("Data Col 2", i, 1);
model.setValueAt("Data Col 3", i, 2);
model.setValueAt("Data Col 4", i, 3);
model.setValueAt("Data Col 5", i, 4);
model.setValueAt("Data Col 6", i, 5);
}
}
}