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 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182
|
class TestTableModel extends JPanel {
public TestTableModel() {
super(new GridLayout(1, 0));
JTable table = new JTable(new MyTableModel());
table.setPreferredScrollableViewportSize(new Dimension(500, 70));
JScrollPane scrollPane = new JScrollPane(table);
setUpResultColumn(table, table.getColumnModel().getColumn(3));
add(scrollPane);
}
public void setUpResultColumn(JTable table, TableColumn resultColumn) {
// Set up the deitor for the result cells
JComboBox comboBox = new JComboBox();
comboBox.addItem("1 - 0");
comboBox.addItem("0.5 - 0.5");
comboBox.addItem("0 - 1");
comboBox.addItem("F - 1");
comboBox.addItem("1 - F");
comboBox.addItem("F - F");
comboBox.addItem("0 - 0");
resultColumn.setCellEditor(new DefaultCellEditor(comboBox));
// Set up tool tips for the sport cells
DefaultTableCellRenderer renderer = new DefaultTableCellRenderer();
renderer.setToolTipText("Click for combo box");
resultColumn.setCellRenderer(renderer);
}
class MyTableModel extends AbstractTableModel {
String[] columnNames = { "Table", "Num pairing", "White", "result",
"Num Pairing", "Black" };
Object[][] data = {
{ new Integer(1), new Integer(1), "Dupont", "1 - 0",
new Integer(3), "Durand" },
{ new Integer(2), new Integer(4), "Martin", "1 - 0",
new Integer(2), "Boulanger" } };
public int getColumnCount() {
return columnNames.length;
}
public int getRowCount() {
return data.length;
}
public String getColumnName(int col) {
return columnNames[col];
}
public Object getValueAt(int row, int col) {
return data[row][col];
}
public Class getColumnClass(int c) {
return getValueAt(0, c).getClass();
}
public boolean isCellEditable(int row, int col) {
/*
* if (3==col) return true; else return false;
*/
return true;
}
public void setValueAt(Object value, int row, int col) {
System.out.println("Setting value at " + row + "," + col + " to "
+ value + "(an instance of " + value.getClass() + ")");
data[row][col] = value;
fireTableCellUpdated(row, col);
}
}
}
// ------------------------------------------------------------------------------------------
class PanneauPrincipal extends JPanel
/* implements Configuration */{
// Variables d'instance
private JMenuBar menuBar = new JMenuBar();
private JMenu menuFichier = new JMenu("Fichier");
private JMenu menuJoueur = new JMenu("Joueur");
private JMenu menuAppariement = new JMenu("Appariement");
private JFrame frame;
// private ListOfPlayer listPlayer;
/** Item du menu fichier */
private JMenuItem itemNew = new JMenuItem("Nouveau");
private JMenuItem itemOpen = new JMenuItem("Ouvrir");
private JMenuItem itemSave = new JMenuItem("Sauver");
private JMenuItem itemQuit = new JMenuItem("Quitter");
/** Item du menu Joueur */
private JMenuItem itemAddPlayer = new JMenuItem("Ajouter joueur");
private JMenuItem itemOutPlayer = new JMenuItem("Sortir joueur");
/** Item du menu Appariement */
void executerActionOuvrir() {
JOptionPane.showMessageDialog(this, "Exécution de l'action Ouvrir");
}
void executerAddPlayer() {
// DialogAddPlayer dialog = new DialogAddPlayer(frame);
// // dialog.setLocationRelativeTo(frame);
//
// if (dialog.returnOK())
// listPlayer.addPlayer(dialog.getName(), dialog.getSurname(), dialog
// .getElo());
}
void executerActionQuitter() {
if (JOptionPane.showConfirmDialog(this,
"Êtes-vous sûr de vouloir quitter", "Confirmation",
JOptionPane.YES_NO_CANCEL_OPTION) == JOptionPane.YES_OPTION)
System.exit(0);
}
// Constructeur
// public PanneauPrincipal(JFrame frame, ListOfPlayer listPlayer) {
public PanneauPrincipal(JFrame frame) {
this.frame = frame;
// this.listPlayer = listPlayer;
menuFichier.setText("Fichier");
menuFichier.add(itemNew);
itemOpen.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
executerActionOuvrir();
}
});
menuFichier.add(itemOpen);
menuFichier.addSeparator();
menuFichier.add(itemSave);
menuFichier.addSeparator();
itemQuit.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
executerActionQuitter();
}
});
menuFichier.add(itemQuit);
itemAddPlayer.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
executerAddPlayer();
}
});
menuJoueur.add(itemAddPlayer);
menuJoueur.add(itemOutPlayer);
setLayout(new BorderLayout());
add(menuBar, BorderLayout.NORTH);
menuBar.add(menuFichier);
menuBar.add(menuJoueur);
}
public static void main(String[] args) {
JFrame frame = new JFrame("toto");
frame.getContentPane().add(new TestTableModel());
frame.setVisible(true);
}
} |