un modo è il seguente:
codice:
import java.awt.Color;
import javax.swing.*;
import javax.swing.table.*;
public class ProvaJTable extends JFrame {
ProvaJTable() {
this.setSize(400,200);
this.setTitle("PlanetTable");
Object[][] cells =
{
{"Mercury", new Double(2400), new Integer(0), Boolean.FALSE, Color.yellow},
{"Venus", new Double(6052), new Integer(0), Boolean.FALSE, Color.yellow}
};
String[] columnNames = {"Planet", "Radius", "Moons", "Gaseous", "Color"};
JTable table = new JTable(cells, columnNames);
JScrollPane pane = new JScrollPane(table);
getContentPane().add(pane);
}
public static void main(String[] args) {
ProvaJTable pjt = new ProvaJTable();
pjt.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
pjt.show();
}
}