Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Swing / AWT / SWT
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Jeanne Boyarsky
Ron McLeod
Paul Clapham
Liutauras Vilda
Sheriffs:
paul wheaton
Rob Spoor
Devaka Cooray
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Carey Brown
Frits Walraven
Tim Moores
Bartenders:
Mikalai Zaikin
Forum:
Swing / AWT / SWT
How to select default value of jRadioButton inside jTable
Tomas Reyes
Greenhorn
Posts: 6
posted 11 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Hello experts.
I create this 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 );
Mi question is how can I select the jRadioButton of the first element of jTable?
Regards
tomrey
Tomas Reyes
Greenhorn
Posts: 6
posted 11 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
I found this 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).
Tomas Reyes
Greenhorn
Posts: 6
posted 11 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
I found how to select with:
table.setValueAt(true, 0, 1);
Thanks a lot anyway
tomrey
With a little knowledge, a
cast iron skillet
is non-stick and lasts a lifetime.
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
Unable to refresh JTable after Updating data into database
Updating Database by editing jtable
Updating Database by editing jtable
jtable
How to make a check on a radio button in Java code without using the Mouse
More...