Suraj Ali
Suraj Ali

Reputation: 21

How to add button to row of JTable?

I have a Swing based application containing a JTable. Now I would like to allow each row to be updated or deleted, using a unique row ID. So I want to add an update and delete button to each row, which have the capability to support an ActionListener. However, I have no idea how to do this using NetBeans.

Upvotes: 1

Views: 1708

Answers (1)

camickr
camickr

Reputation: 324098

To display a button in a column you need to create:

  1. a custom renderer to display the JButton
  2. a custom editor to respond to the mouse click

Read the section from the Swing tutorial on How to Use Tables. The section on:

  1. Using Custom Renders will explain the basics of using a renderer
  2. Using Other Editors will explain the basics of using an editor

Working example are provided in the tutorial that you can download.

You can check out Table Button Column for one approach.

The code uses a single class to implement the custom renderer and editor that you will need for the column to display your text as a button.

Upvotes: 2

Related Questions