Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to include JButton in a JTable?

I have a JTable that stores the results of a database query, so far so good. What I want is for the last column in each table to have a clickible JButton that will open the edit screen for the object represented in that row, and that means the button will need to know the details of the first column in the table from its own row (the ID from the database).

Any advice? I already tried just adding JButtons but they turned into Text when I tried to run it.

like image 691
Benjamin Confino Avatar asked Apr 18 '09 22:04

Benjamin Confino


People also ask

What is JButton used for?

The JButton class is used to create a labeled button that has platform independent implementation. The application result in some action when the button is pushed. It inherits AbstractButton class.


1 Answers

Contrary to the tutorial above, there is a way to do this without a complicated positioning math, custom mouse listeners, and custom table models. Instead, it can be done with a single simple custom class following the pattern described here:

http://web.archive.org/web/20100623105810/http://ivolo.mit.edu/post/A-Simple-Pattern-for-Embedding-Components-into-a-Swing-JTable.aspx

like image 93
Ilya Avatar answered Oct 14 '22 15:10

Ilya