how to add a jcheckbox when the table model initially is not defined.
-
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.
-
Answer:
http://docs.oracle.com/javase/7/docs/api/javax/swing/JTable.html 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 http://docs.oracle.com/javase/tutorial/uiswing/components/table.html#editrender, the default renderer and editor for a column of type Boolean is a JCheckBox. Here's a simple http://stackoverflow.com/a/7137801/230513 that conditions getColumnClass() accordingly. Here's a more complex http://sites.google.com/site/drjohnbmatthews/table that defines a composite type, http://sites.google.com/site/drjohnbmatthews/table#Value, as well as a custom renderer and editor.
user1101703 at Stack Overflow Visit the source
Related Q & A:
- How to add a column header to the dynamic table?Best solution by stackoverflow.com
- How to add a contact to a specific list?Best solution by Stack Overflow
- How to add primary key from multiple table as a foreign key in a table in sql server 2008?Best solution by stackoverflow.com
- How to add a new table to a data source?Best solution by technet.microsoft.com
- How to add a button in a Fragment?Best solution by Stack Overflow
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.