Click here to Skip to main content
15,882,113 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
JCheckbox isn't visible in a particular column of a JTable what to do...?
All other types are OK but not the checkbox

What I have tried:

In file MyTableModel which extends DefaultTableModel I wrote
{
	public MyTableModel(Object row[][],Object colNames[])
	{
		super(row,colNames);
	}
	@Override
	public Class getColumnClass(int col)
	{
		TabStruct tbs=new TabStruct("");
		int totPage=tbs.iPage;
		char[] c=new char[1]; 
//		DateRenderer r=new DateRenderer();
		for(int page=0;page<totPage;page++)
		{
			if(d.dataTp[page][col]=="Number")
				return Integer.class;
			else if(d.dataTp[page][col]=="Date")
				return Date.class;
			else if(d.dataTp[page][col]=="Decimal")
				return	Double.class;
			else if(d.dataTp[page][col]=="Text")
				return String.class;
			else if(d.dataTp[page][col]=="Image")
				return Image.class;
			else if(d.dataTp[page][col]=="bool")
				return boolean.class;
			else
				return String.class;
		}
		return String.class;
	}
Posted
Updated 20-Feb-23 21:50pm
v2
Comments
Richard MacCutchan 21-Feb-23 3:15am    
I don't see any references to JCheckbox in your question.
Member 12712527 21-Feb-23 3:37am    
why do you need checkbox...see the code below

public class jt_jc extends JFrame
{
private JTable table;
private DefaultTableModel model;
public JTable_JCheckBox() {
Random rnd = new Random();
model = new DefaultTableModel(new Object[]{"Check Box1","Check Box2", "Check Box3"}, 0) {
@Override
public Class getColumnClass(int columnIndex) {
return Boolean.class;
}
};
for (int index = 0; index < 10; index++) {
model.addRow(new Object[]{rnd.nextBoolean()});
}
table = new JTable(model);
add(new JScrollPane(table));
setTitle("JCheckBoxJTable Test");
setSize(375, 250);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLocationRelativeTo(null);
setVisible(true);
}
Member 12712527 21-Feb-23 3:41am    
I have already a table with the following datatypes[int,double,string....]
how could i add this to my table
Member 12712527 21-Feb-23 3:47am    
OKay thank you sir I got it. It was a silly mistake of 'boolean' and 'Boolean'

1 solution

Quote:
OKay thank you sir I got it. It was a silly mistake of 'boolean' and 'Boolean'
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900