在Java中单击表上的radiobuttom时如何捕获事件 [英] how to catch event when click on radiobuttom on table in java

查看:84
本文介绍了在Java中单击表上的radiobuttom时如何捕获事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我在Java中有关于jtable的问题.我有一个5列的jtable.五列中的两列是单选按钮列(第2列和第3列:单击第2列的单元格将禁用设置为第3列的单元格,然后单击第3列的单元格将禁用第2列的单元格.)
单击第2列和第3列的任何单元格时如何获取当前行和当前列及值?
我尝试在evnent MouseClick和tableChange中使用但未成功,在mouseClick事件上我无法获取它们,在tableChange事件上有时我可以获取正确但有时我无法获取.

如果知道,请帮助我!

非常感谢!!

Hi all,

I have a problem about jtable in java. I have a jtable with 5 columns. and two of five columns are radio button column(column 2 and column 3: click on cell of column 2 is set disable to cell of column 3 and click on cell of column 3 is disable cell of column2).
How to get current row and current column and value when click on any cell of column 2 and column 3?
I tried to use in evnent MouseClick and tableChange but unsuccessfull, on mouseClick event I can not get them, and on tableChange event sometimes I can get correct but sometimes i can not get correct.

If you know, please help me!

thank you very much!

推荐答案

事件不是捕获"的,但是它们是由事件处理程序处理的,您可以将其提供给控件类的实例.此处详细说明: http://docs.oracle.com/cd /E15051_01/wlw/docs103/guide/controls/conHandlingControlCallbacks.html [ ^ ].

—SA
Events are not "caught", but they are handled with event handlers which you can supply to an instance of a control class. This is explained in detail here: http://docs.oracle.com/cd/E15051_01/wlw/docs103/guide/controls/conHandlingControlCallbacks.html[^].

—SA


有多种方法可以实现.
最简单的方法是在JRadioButton上设置特定的ActionCommand-不是最聪明的方法,而是可行的方法.

更好的方法是自定义JRadioButton并在那里设置一些其他数据.然后,您可以使用Event.getSource()从SelectionListener获取RadioButton.从那里开始,您可以选择如何处理它.
这是一种适合动态GUI创建的方法.
There are multiple ways to get that.
The pretty simplest approach is to set a certain ActionCommand on the JRadioButton - not the smartest, but a working thingy.

Better is to customize the JRadioButton and to set some additional Data there. You can then use Event.getSource() to get the RadioButton from the SelectionListener. From there on it''s your choice how to deal with it.
This is an approach that fits also dynamic GUI creations.


这篇关于在Java中单击表上的radiobuttom时如何捕获事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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