Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Table cell renderer

Reply
Thread Tools

Table cell renderer

 
 
John M
Guest
Posts: n/a
 
      01-27-2004
Hello,

I have a problem with a cell renderer. I want to make a column with
checkboxes, and I write the following code. When I edit the cell it use a
checkbox editor, but if I leave the cell it returns to a text (true/false).
What can I do?

model.addColumn("Col1");
model.insertRow(0,new Boolean[]{new Boolean(false)});
jTable1.getColumnModel().getColumn(0).setCellEdito r(new
DefaultCellEditor(new JCheckBox()));
jTable1.getColumnModel().getColumn(0).setCellRende rer(new
DefaultTableCellRenderer());

Thanks!



 
Reply With Quote
 
 
 
 
Christian Kaufhold
Guest
Posts: n/a
 
      01-28-2004
Please use comp.lang.java.gui for GUI questions.

John M <(E-Mail Removed)> wrote:


> I have a problem with a cell renderer. I want to make a column with
> checkboxes, and I write the following code. When I edit the cell it use a
> checkbox editor, but if I leave the cell it returns to a text (true/false).
> What can I do?


DefaultTableCellRenderer is not suitable for displaying boolean values
as a checkbox. The only standard renderer that is is JTable's default
renderer for Boolean.class.


> model.addColumn("Col1");


DefaultTableModel.addColumn has usually undesirable side-effects,
(destroying the current column model settings). It is best to
*start* with the current number of columns if known in advance.


> model.insertRow(0,new Boolean[]{new Boolean(false)});
> jTable1.getColumnModel().getColumn(0).setCellEdito r(new
> DefaultCellEditor(new JCheckBox()));
> jTable1.getColumnModel().getColumn(0).setCellRende rer(new
> DefaultTableCellRenderer());


jTable1.getColumnModel().getColumn(0).setCellRende rer
(jTable1.getDefaultRenderer(Boolean.class));


Alternatively, just rely on the column-class-based default renderers/
editors and make getColumnClass(0) == Boolean.class.



Christian
--
And in short, I was afraid.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Why doesn't cell renderer work ??? zbyszek.kielich@gmail.com Java 4 09-30-2008 06:15 AM
JComboBox as a Cell Renderer in a table column question noident@my-deja.com Java 2 07-11-2006 11:21 PM
[JTable] Alignment in custom cell renderer Branko Kaucic Java 4 09-13-2005 07:03 AM
How do I have a table cell fetch another page to display within the cell? Phillip Roncoroni HTML 14 04-05-2004 05:58 PM
Different Renderer type per row in same column of JTable? RobE Java 2 08-12-2003 06:12 AM



Advertisments