访问JTable单元格组件 [英] Access JTable cell component

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

问题描述

好吧,我有一个JTable,我在每个单元格上显示一个JList.为此,我必须实现TableCellRenderer并扩展DefaultCellEditor.这是我返回要在GUI中呈现的实际JList的地方.

Ok I have a JTable where I'm displaying a JList on every cell. To do this I had to implement TableCellRenderer and extend DefaultCellEditor. Here is where I return the actual JList to be rendered in GUI.

我想做的是,当用户从JList取消选择一个项目时,我也想从被单击的列开始为该表行取消所有JList的所有项目.

What I want to do is when user de-selects an item from a JList, I want to also de-select all items for all JLists for that table row starting at the clicked column.

我的问题是我想不出一种方法来取消选择当前单击的表格列之后的所有项目.我只能访问的是DefaultListModel.我想我需要访问实际的JList才能删除所有选中的项.

My problem is that I can't figure out a way to de-select all items that come after the current clicked table column. All I can access is this DefaultListModel. I guess I need to access the actual JList in order to remove all selected items.

以下是我正在使用的方法.任何想法如何做到这一点?谢谢.

Below is method I'm using. Any ideas how to do this? Thanks.

public void deselectFromLocation(int row_, int column_){
        DefaultTableModel dtm = (DefaultTableModel) table1.getModel();

        int cols = dtm.getColumnCount();
        for(int i=column_; i<cols;i++){
            PCSListModel lm = (PCSListModel) dtm.getValueAt(row_, i);
            //How can I access the actual JList object in order to  remove all selected items? 
            //The PCSListMode is DefaultListModel and has no access to JList object. Thanks.


        }

    }

推荐答案

大概是,渲染器和编辑器从TableModel获取现有的选择状态,也许更新了ListSelectionModel的实例,该实例用作准备使用的组件.您可以在实现stopCellEditing()的过程中更新 other 模型值.您的TableModel必须为其他单元触发一个合适的TableModelEvent;对于正在编辑的值,请这样做.可以在此处看到一个相关示例.

Presumably, your renderer and editor obtain the existing selection state from your TableModel, perhaps updating an instance of ListSelectionModel that is used as part of preparing the component for use. You can update the other model value(s) in your implementation of stopCellEditing(). Your TableModel will have to fire a suitable TableModelEvent for the other cells; do not do so for the value being edited. A related example is seen here.

这篇关于访问JTable单元格组件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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