为突出显示的JList项动态显示计数器 [英] Showing a counter dynamically for JList items highlighted

查看:87
本文介绍了为突出显示的JList项动态显示计数器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个我为工作创建的程序。该程序获取上传的文件,读取它,并将数据放入GUI中的JList。 GUI实际上有两个列表,用户可以通过使用JList突出显示它们然后按箭头移动项目来在左右列表之间移动项目。这些列表是多区间选择。

I have a program that I created for work. This program takes an uploaded file, reads it, and puts the data into a JList in the GUI. The GUI actually has two lists and the user is able to move items between the left and right list by highlighting them like usual with a JList and then hitting an arrow to move the items. The lists are multiple-interval selection.

我想添加的一个小小的补充是某种类型的计数器,它向用户显示他们在实际移动之前选择了多少项列表之间。这需要是动态的,所以如果用户保持控制并开始点击计数器将继续更新突出显示的项目数。

One small addition I would like to add is some type of counter that shows the user how many items they have selected before they actually move them between lists. This would need to be dynamic so if the user holds control down and begins clicking the counter will continue to update the number of highlighted items.

因为列表通常很大并且用户可能需要在列表之间移动奇数个事务(左侧列表中的Think 300事务,并且用户需要准确地移动50个),拥有此计数器将是有益的。

As the lists are often quite large and a user might need to move an odd number of transactions between the lists (Think 300 transactions in left list and the user needs to move exactly 50) it would be beneficial to have this counter.

谁能想到如何做到这一点?我不确定如何添加动作侦听器来单击项目。如果我需要再详细说明,请告诉我。

Can anyone think of how this could be done? I'm not sure how to add an action listener to just clicking on the items. Please also let me know if I need to elaborate any more.

一般来说,我的问题是,我是否可以创建一个动作侦听器,仅用于当用户单击JList中更新当前所选索引的计数器的项目时?当他们不再选择一个指标时,它也需要改变。

Generally my question is can I create an action listener just for when a user clicks a item in a JList that updates a counter for the current selected indices? Also it would need to change when they no longer have selected an indice.

推荐答案

用你的JList注册一个ListSelectionListener。

Register a ListSelectionListener with your JList.

听众可以只需查询选择了多少行,并将面板中的数字更新为该数字。也许使用getSelectedValues()。size()。

The listener could simply query how many rows are selected and update the number in the panel to that. Perhaps use getSelectedValues().size().

http://docs.oracle.com/javase/8/docs/api/javax/swing/JList.html#addListSelectionListener -javax.swing.event.ListSelectionListener-

这篇关于为突出显示的JList项动态显示计数器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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