Balázs Édes
Balázs Édes

Reputation: 13807

JTable from TableModel - add Buttons to each row

I have a school project where I need to create a gui for a database. The database contains 3 tables:

  1. a table for pizzas

  2. a table for toppings

  3. And a table, which contains the foreign keys for the pizzas and toppings. Basically this table declares, what toppings does a pizza have.

I can display now the pizza table in a JTable through a custom TableModel (the table model communicates with the database).

But now I would like to add two columns for the table. These columns would contain two buttons in each row, one for deleting the actual row, one for opening a dialog, which enables to edit the current pizza (add toppings, change attributes, etc.).

How can I add these columns, if I "feed" the JTable from a custom table model? Do I need to modify the table model, or the JTable?

Upvotes: 1

Views: 3155

Answers (1)

mKorbel
mKorbel

Reputation: 109813

add JButton (with correct workaround for TableCellRenderer and TableCellEditor) in the JTable's cell is one hardiest jobs in the Swing,

1) @camickrs Table Button Column

2) add JPanel with JComponents to the JTable's column

Upvotes: 3

Related Questions