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

问题描述

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

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

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

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

我该怎么做?

这是代码


  • GUI_g:

  • ProgramTableModel:

  • 处理:

  • 主要:

  • GUI_g: http://pastebin.com/J3qtjn8J
  • ProgramTableModel: http://pastebin.com/Dwkc9Cz3
  • Processing: http://pastebin.com/qHnkvCbr
  • Main: http://pastebin.com/K4yGYX9H

我猜它会将所选行中的数据检索到一个数组,拆分它,并把它放入jtextareas。我怎么能这样做?

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 ?

推荐答案

我是这样做的:

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 - 选择行单击事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-21 00:53