Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Radiobutton in Jtable

 
abhijeet nagare
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello guys
i am using developing swing appication
and inserting radiobutton in jTABLE
BUT instead of that i am getting its true/false value...
pleasse give me solution...if any

my code is...

/**
*
*/
package appointmentFinal;


import java.awt.FlowLayout;

import javax.swing.*;
import javax.swing.table.DefaultTableModel;

public class Jtable1 extends JFrame
{
JTable t;
Jtable1()
{
String col[]={"Employee","Start_Date","Client","Product or Services","tax","cost"};

JCheckBox ch=new JCheckBox();
Object [][] data = {
{"Kathy", "Smith",
"Snowboarding", new Integer(5), ch,1},
{"John", "Doe",
"Rowing", new Integer(3), new Boolean(true),1},
{"Sue", "Black",
"Knitting", new Integer(2), new Boolean(false),1},
{"Jane", "White",
"Speed reading", new Integer(20), new Boolean(true),1},
{"Joe", "Brown",
"Pool", new Integer(10), new Boolean(false),1}
};

DefaultTableModel tb =new DefaultTableModel(data,col);
t=new JTable( tb);


for(int i=0;i<6;i++)
{
t.getColumnModel().getColumn(i).setPreferredWidth(150);
t.setRowHeight(30);
}



add(t);
setLayout(new FlowLayout());
setSize(700, 500);
setLocation(300, 150);
setTitle("Ticket_Information");
setVisible(true);


}
public static void main (String []args)
{
new Jtable1();
}
}




 
Paul Mrozik
Ranch Hand
Posts: 117
Chrome Mac Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
abhijeet nagare wrote: hello guys
i am using developing swing appication
and inserting radiobutton in jTABLE
BUT instead of that i am getting its true/false value...
pleasse give me solution...if any



Please try using the Code button, it makes things easier to read.

As far as your question goes, have a look at this:



It does exactly what you want it to do. You're creating a and that's what you get in the table.

If you want a JRadioButton in your cell, you'll need to read about Cell Renderers



 
Darryl Burke
Bartender
Posts: 5132
11
Java Netbeans IDE Opera
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
... and cell editors too.
 
abhijeet nagare
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can you please eloborate with some example ..please...
 
Darryl Burke
Bartender
Posts: 5132
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Read the API for JTable and follow the link to the Swing tutorial on How to Use Tables where you will find several examples.
 
abhijeet nagare
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Darryl Burke wrote:Read the API for JTable and follow the link to the Swing tutorial on How to Use Tables where you will find several examples.



thanks bro... i am working on it...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic