如何使删除按钮删除JTable中的行? [英] How to make delete button to delete rows in JTable?

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

问题描述

我尝试按键删除但是当我选择单元格并按删除按钮时,它会输入所选单元格而不是删除整行。如何在选择单元格时禁用删除按钮不执行任何操作?

I tried to make keystroke Delete but when I select cell and press delete button it enter in the selected cell instead to delete the whole row . How I can disable Delete button to do nothing when cell is selected?

noo。我的GUI上有删除按钮,但我想为此按钮设置键盘快捷键。我想在键盘上设置删除按钮来调用删除方法。但是当我在选择单元格时按下它时,它会输入单元格而不是删除整行

noo. I have delete button on my GUI but I want to make keyboard shortcut to this button. I want to make delete button on my keyboard to call delete method. But when I press it when cell is selected it enter in the cell instead to delete the entire row

推荐答案

DefaultCellEditor 对于许多 JTable 单元格类型委托给 JTextField ,它将 Delete 键绑定到 delete-next 行动。要抢占默认行为,您必须从 DefaultCellEditor 中删除​​现有绑定,如 如何使用键绑定:如何制作和删除键绑定 。您可以使用自己的绑定替换它,如示例所示; 此处显示典型的 DefaultCellEditor

The DefaultCellEditor for many JTable cell types delegates to a JTextField, which binds the Delete key to the delete-next action. To preempt the default behavior, you'll have to remove the existing binding from DefaultCellEditor, as shown in How to Use Key Bindings: How to Make and Remove Key Bindings. You can replace it with your own binding, as shown in this example; a typical DefaultCellEditor is shown here.

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

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