JTable - 选定行单击事件 [英] JTable - Selected Row click event

查看:44
本文介绍了JTable - 选定行单击事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 Jtable,它通过 AbstractTableModel 填充了链表.

我想要做的是当我在 JTable 中的一行上单击(鼠标左键单击)时,链接列表是搜索(在这种情况下它包含电影标题)并在 Jtextboxes 中显示链接列表中的值

我该怎么做?

这是代码

我猜它会将选定行中的数据检索到一个数组中,将其拆分,然后放入 jtextareas 中.我该怎么做?

解决方案

我是这样做的:

table.getSelectionModel().addListSelectionListener(new ListSelectionListener(){公共无效值更改(ListSelectionEvent 事件){//在这里做一些动作,例如//打印选定行的第一列值System.out.println(table.getValueAt(table.getSelectedRow(), 0).toString());}});

此代码对鼠标点击和键盘上的项目做出反应.

I have a Jtable that is populated with a linkedlist through an AbstractTableModel.

What I want to do is when I click (left-mouse click) on a row in the JTable, the linkedlist is search (in this case it contains movie titles) and displays the values in the linked list in Jtextboxes

How do I do this?

Here is the code

My guess it retrieve the data from the selected row into an array, split it, and put it into the jtextareas. How can I do this ?

解决方案

Here's how I did it:

table.getSelectionModel().addListSelectionListener(new ListSelectionListener(){
        public void valueChanged(ListSelectionEvent event) {
            // do some actions here, for example
            // print first column value from selected row
            System.out.println(table.getValueAt(table.getSelectedRow(), 0).toString());
        }
    });

This code reacts on mouse click and item selection from keyboard.

这篇关于JTable - 选定行单击事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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