0

how to add a jcheckbox when the table model initially is not defined.

I have populated the jtable with data from database, but now I need to add a jcheckbox used for selection of desired record.

I can add jcheckbox to jtable if the datatable rows are perdefined with boolean class. But as I am using a database to read from I am bit confused.

any help is welcome.

trashgod
  • 203,806
  • 29
  • 246
  • 1,045
user1101703
  • 21
  • 1
  • 5

1 Answers1

2

JTable relies on its TableModel to determine what to display. Although only existing rows can be shown, you can insert an uncommitted row in the model for editing. What and when to commit are entirely up to your application.

As discussed in How to Use Tables: Concepts: Editors and Renderers, the default renderer and editor for a column of type Boolean is a JCheckBox. Here's a simple example that conditions getColumnClass() accordingly. Here's a more complex example that defines a composite type, Value, as well as a custom renderer and editor.

Community
  • 1
  • 1
trashgod
  • 203,806
  • 29
  • 246
  • 1,045