简体   繁体   English

如何在Jlist中获取一个条目以与另一个JList中的条目一起使用?

[英]How to get one entry in a Jlist to work with entries in another JList?

Bear with me. 忍受我。 I have a denist program with 3 JList's. 我有一个带有3个JList的denist程序。 A patient JList that adds patients, a history jlist that adds the patients history and an invoice history that should link with the history jlist and the patient jlist. 添加患者的患者JList,添加患者历史的历史列表和应与历史列表和患者列表链接的发票历史。 I have them all writing to each Jlist respectably but my aim is: when i click on a patient , their history will pop up in the history JList and the invoice will appear in the Invoice Jlist. 我让他们都分别写信给每个Jlist,但是我的目标是:当我单击一个患者时,他们的历史记录将在历史记录JList中弹出,并且发票将出现在Invoice Jlist中。

How would i go about this? 我将如何处理? I have id's in each jlist. 我在每个jlist中都有ID。 I think this would be the right way to go about it. 我认为这是正确的解决方法。

More than happy to send the program via email if needed. 如果需要,非常乐意通过电子邮件发送程序。

Need help!! 需要帮忙!!

Thanks. 谢谢。

Well, just add ListSelectionListener(s) to your JLists and when the selection changes find the appropriate object for your other JLists to display. 好吧,只需将ListSelectionListener(s)添加到您的JLists中,并且当选择更改时,可以找到适合您的其他JLists显示的对象。
You can call list.getModel().getElementAt(i) to get the elements contained in the list. 您可以调用list.getModel().getElementAt(i)来获取列表中包含的元素。 Find the appropriate one by whatever mechanism you have to identify linked items. 通过识别链接项的任何机制找到合适的链接。 Once you have the item just call list.setSelectedValue(yourObject, shouldScroll) and that's it. 有了项目后,只需调用list.setSelectedValue(yourObject, shouldScroll)就可以了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM