bonjour,
j ai un problème (sinon je posterai pas :p), je voudrai dans une colonne de ma JTable mettre un JRadioButton, et c'est la que ca coince... Quand je clique sur ma colone ca marche, enfin, il m'affiche un bouton, mais la ligne du dessous m'affiche "javax.swing.JRadioButton"... j'ai un CellRenderer perso et un TableCellEditor, mais y a un truc qui va pas...
voila mon cellEditor
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
 
public class TableCellRadioEditor extends AbstractCellEditor implements TableCellEditor {
 
	private static final long serialVersionUID = 1L;
	private Boolean b;
	private JRadioButton radio = null;
 
	public TableCellRadioEditor() {
		radio = new JRadioButton();
	}
 
	public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected,
			int row, int column) {
 
		System.out.println( value.getClass() );
 
		if( value instanceof Boolean ) {
			b = (Boolean) value;
			radio.setSelected(b);
		}
 
		return radio;
	}
 
	public Object getCellEditorValue() {
		return radio;
	}
}
le cellRenderer
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
public class TableCellRadioRender implements TableCellRenderer {
 
	JRadioButton radio = null;
 
	public TableCellRadioRender(){
		radio = new JRadioButton();
	}
 
	public Component getTableCellRendererComponent(JTable table, Object value, 
boolean isSelected,boolean hasFocus, int row, int column) {
		Boolean b = (Boolean)value;
	    radio.setSelected( b );
	    return radio;
	}
 
	public Object getCellEditorValue() {
		return radio;
	}
}
et je les passe comme ca a ma Table :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
 
TableModel jTable1Model = new DefaultTableModel(
		new Object[][] { { "ligne1", new JRadioButton()  },
					{ "ligne2", new JRadioButton() } },
new String[] { "Machine Cible", "Connexion par défaut" });
jTable1 = new JTable();
jTable1.getTableHeader().setReorderingAllowed(false);
jScrollPane1.setViewportView(jTable1);
jTable1.setModel(jTable1Model);
 
TableColumn col = jTable1.getColumnModel().getColumn(1);
col.setCellEditor( new TableCellRadioEditor() );
jTable1.setDefaultRenderer(Boolean.class, new TableCellRadioRender() );
il me manque quoi ?