Jithin Sebastian
Jithin Sebastian

Reputation: 581

Use JTable entries as buttons

I have a JTable which contains names returned from a search in database. I want to use the names as buttons, when we click on them the program redirect to another frame with more details of the nameholder. Can I do that ?

Upvotes: 1

Views: 51

Answers (2)

Audrius Meškauskas
Audrius Meškauskas

Reputation: 21748

This is easy to do, add the mouse listener to the table and use columnAtPoint and rowAtPoint to determine what has been clicked.

If you want a table cell to look like a button, set a renderer that uses JButton.

Upvotes: 2

camickr
camickr

Reputation: 324118

I want to use the names as buttons, when we click on them the program redirect to another frame with more details of the nameholder.

You need to create a custom renderer and editor for your table. Read the section from the Swing tutorial on Concepts: Editors and Renderers for basic information.

Then you can check out Table Button Column which is an example of a render/editor that you can use. You will need to provide your own custom Action to display the details.

Upvotes: 1

Related Questions