Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: How to select default value of jRadioButton inside jTable

  1. #1
    Junior Member tomrey's Avatar
    Join Date
    Feb 2013
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default How to select default value of jRadioButton inside jTable

    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
    Last edited by tomrey; February 26th, 2013 at 11:48 AM. Reason: Some programmer told me is misleading my question


  2. #2
    Junior Member tomrey's Avatar
    Join Date
    Feb 2013
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: How to select default value of jRadioButton inside jTable

    I found how using:

    table.setValueAt(true, 0, 1);

    Thanks a lot anyway.
    Regards
    tomrey

Similar Threads

  1. Replies: 21
    Last Post: November 27th, 2012, 10:58 PM
  2. can we select default writing language to JTextField
    By bravvve in forum AWT / Java Swing
    Replies: 0
    Last Post: March 10th, 2011, 03:51 AM
  3. Buttons don't work on using JRadioButton
    By neo_2010 in forum AWT / Java Swing
    Replies: 4
    Last Post: July 11th, 2009, 11:37 AM

Tags for this Thread