Bonjour a tous, j'ais regardé presque tout les topics sur la façon de mettre une Colonne de ma Jtable avec des Jcombobox y compris les tutos de sun, mais aucune n'a fonctionnée...
Donc je fais appel a vous...
Voici le code pour mettre une jcombobox que j'utilise mais qui ne fonctionne pas :
(la Jcombobox ne s'affiche pas, seul le valeur 6 qui est définit dans mon arraylist s'affiche dans cette colonne).
Et voici le code de ma SpecialTableModelObject
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 package myPack; import java.util.ArrayList; import javax.swing.DefaultCellEditor; import javax.swing.ImageIcon; import javax.swing.ListSelectionModel; import javax.swing.table.DefaultTableCellRenderer; import javax.swing.table.TableColumn; public class frame_search_info extends javax.swing.JFrame { public frame_search_info() { ... //On initialize les données de la Arraylist<object[]> initData(); //On initialise le model de la Jtable initModel(); ... } private void initData(int type){ ImageIcon myIconNext=new ImageIcon(System.getProperty("user.dir")+"/data/next.png"); for(int z=0;z<10;z++){ data_list.add(new Object[]{ myIconNext, myIconNext, "2", "3", "4", "5", "6"}); } } private void initModel(){ table_list.setModel(new SpecialTableModelObject(data_list, new String[] { "0", "1", "2", "3", "4", "5", "comboColumn"})); javax.swing.JComboBox myComboBox = new javax.swing.JComboBox(); myComboBox.addItem("choice1"); myComboBox.addItem("choice2"); myComboBox.addItem("choice3"); table_list.getColumnModel().getColumn(6).setCellEditor(new DefaultCellEditor(myComboBox)); } private ArrayList<Object[]> data_list=new ArrayList<Object[]>(); .... private org.jdesktop.swingx.JXTable table_list; // End of variables declaration }
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 package myPack; import java.util.ArrayList; import javax.swing.table.AbstractTableModel; public class SpecialTableModelObject extends AbstractTableModel { private static final long serialVersionUID = 1; private String[] columnNames; private ArrayList<Object[]> data = new ArrayList<Object[]>(); public SpecialTableModelObject( ArrayList<Object[]> dat, String[] cols){ super(); columnNames = cols; data = dat; } public SpecialTableModelObject( ArrayList<Object[]> dat){ super(); data = dat; } public void misajour( ArrayList<Object[]> dat){ data = dat; } public int getColumnCount() { return columnNames.length; } public int getRowCount() { return data.size(); } public void setColumn(String[] column){ columnNames = column; } public String getColumnName(int col) { return columnNames[col]; } public Object getValueAt(int row, int col) { Object[] v = data.get(row); return v[col]; } public Class<?> getColumnClass(int c) { return getValueAt(0, c).getClass(); } public boolean isCellEditable(int row, int col) { return false; } public void setValueAt(String value, int row, int col) { Object[] v = data.get(row); v[col] = value; fireTableCellUpdated(row, col); } }
Je vous remercie d'avance pour toute l'aide que vous pourrez m'apporter![]()
Partager