Hi experts.
I am new in java but I've spent time learning. I created a jTable with jRadioButton inside using JDBC, my code:
MyObjectManager manager = new MyObjectManager(); try { Connection conn = dbConnection(); PreparedStatement pre = conn.prepareStatement("Select Clave_Familia as Cve, Descripcion_Familia as Familia from famMat_Familias order by Clave_Familia"); ResultSet rs = pre.executeQuery(); while(rs.next()) { object = new MyObject(rs.getString(1)+" "+rs.getString(2)); manager.addObject(object); } } catch(SQLException e ) { System.out.print(e); } table = new JTable(new MyTableModel(manager)); table.setRowHeight(20); TableColumn column = table.getColumnModel().getColumn(1); column.setCellEditor(new RadioButtonCellEditorRenderer()); column.setCellRenderer(new RadioButtonCellEditorRenderer()); table.getColumnModel().getColumn(0).setResizable(false); table.getColumnModel().getColumn(0).setPreferredWidth(480); // Asignar gFam del radio button seleccionado if (Global.gFam != null) { nTotFilas = table.getRowCount()-1; sFam = Global.gFam.toString(); for(nFila=0; nFila<nTotFilas+1 ; nFila++) { sCveNew = table.getValueAt(nFila, 0).toString(); if(sCveNew.substring(0, 2).equals(sFam.substring(0, 2))) { // System.out.println("I found it"); // Check radio button of table in column one // table.getModel().setValueAt(this, 1, 0); } } } table.getColumnModel().getColumn(1).setResizable(false); table.getColumnModel().getColumn(1).setPreferredWidth(70); //:) Falta seleccionar la primera familia // table.changeSelection(1, 0, true, true); setTitle( "Codificación de Materiales" ); setSize( 1000, 750 ); setBackground( Color.gray ); JPanel topPanel = new JPanel(); topPanel.setLayout( new BorderLayout() ); getContentPane().add( topPanel ); //creaCodifica(); // Codifica jpCodifica = new JPanel(); // Crea los Tabs jpCodifica.setLayout( null ); JScrollPane jspFam = new JScrollPane(table); // Familia jspFam.setBounds(10, 10, 300, 630); jpCodifica.add( jspFam );
I found his sample code:
import java.applet.Applet; import java.awt.Checkbox; import java.awt.CheckboxGroup; /* <applet code="SetSelectedRadioButtonExample" width=200 height=200> </applet> */ public class SetSelectedRadioButtonExample extends Applet{ CheckboxGroup lngGrp = null; public void init(){ //create group lngGrp = new CheckboxGroup(); //create checkboxes and add to group Checkbox java = new Checkbox("Java", lngGrp, false); Checkbox cpp = new Checkbox("C++", lngGrp, false); Checkbox vb = new Checkbox("VB", lngGrp, false); //add radio buttons add(java); add(cpp); add(vb); lngGrp.setSelectedCheckbox(java); } }
My question is how can I do the instruction
lngGrp.setSelectedCheckbox(java);
On my first code (I use JDBC for populate my jTable with jRadioButtons).
Thanks in advance
tomrey