1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
| import java.awt.*;
import javax.swing.*;
public class Table extends JFrame {
// Noms des colonnes
String[] nomsColonnes = {"Produits", "Code", "Prix"};
// Données du tableau
Object[][] donnees = {{"Chaussures", new Integer(15),"500.00"},
{"Pantalons", new Integer(32),"160.00"},
{"Chemises", new Integer(14),"145.00"},
{"Pulls", new Integer(9),"180.00"}};
JPanel panel;
JTable table;
JScrollPane sc;
public Table() {
super(" Table");
panel = new JPanel();
table = new JTable(donnees, nomsColonnes);
table.setPreferredScrollableViewportSize(new Dimension(300, 80));
table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
panel.add(table);
sc = new JScrollPane(panel);
add(sc);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Dimension d1 = getToolkit().getScreenSize();
Dimension d2 = this.getSize();
setLocation(d1.width / 2 - d2.width / 2, d1.height / 2 - d2.height / 2);
}
public static void main(String[] args) {
Table table = new Table();
table.pack();
table.setVisible(true);
}
} |
Partager