如何在JTable的行中添加按钮? [英] How to add button to row of JTable?

查看:601
本文介绍了如何在JTable的行中添加按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含JTable的基于Swing的应用程序.现在,我想使用唯一的行ID来更新或删除每一行.因此,我想向每行添加一个更新和删除按钮,它们具有支持ActionListener的功能.但是,我不知道如何使用NetBeans做到这一点.

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.

推荐答案

要在列中显示按钮,您需要创建:

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

  1. 用于显示JButton的自定义渲染器
  2. 用于响应鼠标单击的自定义编辑器

如何使用表中阅读Swing教程中的部分.关于:

  1. Using Custom Renders将解释使用渲染器的基本知识
  2. Using Other Editors将解释使用编辑器的基本知识
  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.

这篇关于如何在JTable的行中添加按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆