This week's book giveaway is in the JavaScript forum.
We're giving away four copies of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js and have Paul Jensen on-line!
See this thread for details.
Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

to add a JCheckBox in a JTable cell  RSS feed

 
kiran manohar
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
how can one add a JCheckBox in a JTable cell.i have 4 rows and 5 columns. the fifth column should have a JCheckBox in it.another thing, how to dynamically add data from my database to the JTable
any ideas.
Regards
Kiranmanohar
 
Chris Brat
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi there,
here is a link to the java tutorial...
It gives very comprehensive information on all the swing components and how to manipulate them. 'The answers you seek are inside' (I know because thats where i found them)
http://java.sun.com/docs/books/tutorial/uiswing/

chris
 
Pascal Got
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also check
this out ....

Pascal
 
kiran manohar
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
thanx for the links. the second one fits my bill to the core. but i got a slight problem how can i dyanmically populate the Object[][] data for the row in the JTable instead of making it static. i will be getting the data from a oracle table.
Thanks Once again
Regards
Kiranmanohar
 
Jose Botella
Ranch Hand
Posts: 2120
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your custom model might extend from AbstractTableModel. A method declared in such class might be responsible for stablishing the connection and populating a new instance of the storing structure of the model with the results of the query.
This menthod would be called by an action listener but creating its ownn thread to avoid clogging the event-dispatching thread.
When finished, this method could notify the table that new data needs to be presented to the user:
(JTable implements TableModelListener)
SwingUtilities.invokeLater(
new Runnable() {
public void run() {
myTable.tableChanged(new TableModelEvent(myModel));
}
}
);
You might find also interesting Detecting data changes from the Java Tutorial.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!