Table cell renderer

Discussion in 'Java' started by John M, Jan 27, 2004.

  1. John M

    John M Guest

    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).setCellEditor(new
    DefaultCellEditor(new JCheckBox()));
    jTable1.getColumnModel().getColumn(0).setCellRenderer(new
    DefaultTableCellRenderer());

    Thanks!
     
    John M, Jan 27, 2004
    #1
    1. Advertising

  2. Please use comp.lang.java.gui for GUI questions.

    John M <> 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).setCellEditor(new
    > DefaultCellEditor(new JCheckBox()));
    > jTable1.getColumnModel().getColumn(0).setCellRenderer(new
    > DefaultTableCellRenderer());


    jTable1.getColumnModel().getColumn(0).setCellRenderer
    (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.
     
    Christian Kaufhold, Jan 28, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. RobE
    Replies:
    2
    Views:
    2,065
    =?ISO-8859-1?Q?J=F6rg_Marti?=
    Aug 12, 2003
  2. Branko Kaucic
    Replies:
    4
    Views:
    13,547
    Branko Kaucic
    Sep 13, 2005
  3. Phillip Roncoroni
    Replies:
    14
    Views:
    1,113
    Toby A Inkster
    Apr 5, 2004
  4. Replies:
    2
    Views:
    2,307
  5. Replies:
    4
    Views:
    758
Loading...

Share This Page