在JList中选择一个项目时,我将如何编码? [英] How would I code when a item has been selected in a JList?

查看:77
本文介绍了在JList中选择一个项目时,我将如何编码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有5个选项的JList,当其中一个项目被选中或单击时,我希望它旁边的文本区域显示与单击的项目有关的一段文本.它应该对列表中的每个项目都执行此操作,但是我似乎找不到在API中执行该操作的方法

I have a JList with 5 options in it and when one of the items becomes selected or clicked i want the text area next to it to show a paragraph of text relative to the item clicked. It should do this for each item in the list but I cant seem to find how to do it in the API

我的程序如何知道JList中的一个项目是否被选中,以便我可以处理数据?

How would my program know if an item in the JList was selected so I can work with the data?

推荐答案

使用

Use addListSelectionListener. You can create a subclass (anonymous or not) of ListSelectionListener that does the work you want.

myList.addListSelectionListener(new ListSelectionListener()
{
  public void valueChanged(ListSelectionEvent ev)
  {
    // handle ev
  } 
});

这篇关于在JList中选择一个项目时,我将如何编码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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