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 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
| package tp;
import java.awt.Dimension;
import javax.swing.DefaultCellEditor;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.TableColumn;
public class TestModeleTable extends JPanel{
private static final long serialVersionUID = 1L;
public TestModeleTable() {
String[][] data={{"CM04-09IUT0283","kjsdbckdzala","14.23","20","Admis en classe supèrieur"},{"CM04609IUT0013","ljkzbachazvbc","14.23","10","Exclu pour conduite"},{"CM04609IUT0025","TOTO TATA Titi","09","50","Admis en classe supèrieur"}};
JTable table = new JTable(new MonModele(data));
table.setPreferredScrollableViewportSize(new Dimension(500, 70));
table.setFillsViewportHeight(true);
//Create the scroll pane and add the table to it.
JScrollPane scrollPane = new JScrollPane(table);
//Fiddle with the Sport column's cell editors/renderers.
setUpSportColumn(table, table.getColumnModel().getColumn(4));
//Add the scroll pane to this panel.
add(scrollPane);
}
public void setUpSportColumn(JTable table,
TableColumn DecisionColumn) {
//Set up the editor for the sport cells.
JComboBox comboBox = new JComboBox();
comboBox.addItem("Admis en classe supèrieur");
comboBox.addItem("Admis au rattrappage");
comboBox.addItem("Admis à redoubler");
comboBox.addItem("Redouble en cas d'echec");
comboBox.addItem("Exclu en cas d'echec");
comboBox.addItem("Exclu pour conduite");
DecisionColumn.setCellEditor(new DefaultCellEditor(comboBox));
// Set up tool tips for the sport cells.
ColorRenderer renderer =
new ColorRenderer();
renderer.setToolTipText("Click for combo box");
DecisionColumn.setCellRenderer(renderer);
}
private static void createAndShowGUI() {
//Create and set up the window.
JFrame frame = new JFrame("TableRenderDemo");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//Create and set up the content pane.
TestModeleTable newContentPane = new TestModeleTable();
newContentPane.setOpaque(true); //content panes must be opaque
frame.setContentPane(newContentPane);
//Display the window.
frame.pack();
frame.setVisible(true);
}
public static void main(String[] args) {
//Schedule a job for the event-dispatching thread:
//creating and showing this application's GUI.
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI();
}
});
}
} |
Partager