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. Advertisements

  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. Advertisements

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. Mark Goldin

    Table in a cell of another table

    Mark Goldin, Aug 19, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    434
    Mark Goldin
    Aug 19, 2004
  2. Branko Kaucic
    Replies:
    4
    Views:
    13,954
    Branko Kaucic
    Sep 13, 2005
  3. Phillip Roncoroni
    Replies:
    14
    Views:
    1,396
    Toby A Inkster
    Apr 5, 2004
  4. Replies:
    2
    Views:
    2,776
  5. sdf
    Replies:
    3
    Views:
    2,461
  6. Replies:
    4
    Views:
    911
  7. Symphony

    add hyber link to table or table cell web control

    Symphony, Mar 15, 2005, in forum: ASP .Net Web Controls
    Replies:
    1
    Views:
    606
    Ken Cox [Microsoft MVP]
    Mar 16, 2005
  8. Replies:
    7
    Views:
    372
    Lasse Reichstein Nielsen
    Jul 11, 2005
Loading...