简体   繁体   English

在JSwing中一次显示两个列表的组合

[英]Displaying a combination of two lists at a time, in JSwing

My problem is I have a List<String> of Files and List<InetAddress> of thier IP Addresses with me. 我的问题是我有一个List<String> of Files和List<InetAddress>和我的IP地址。 I want to display them TOGETHER ie in the form of FILENAME --- IP as a JList in Swing; 我想将它们一起显示,即以FILENAME的形式--- IP作为Swing中的JList; so that the user understands which file is there at which place (IP Address). 这样用户就可以了解哪个文件位于哪个位置(IP地址)。 After that I want to use a double click event which would open that file, hence I want them together. 之后,我想使用双击事件打开该文件,因此我希望它们在一起。 How do I do that? 我怎么做? Is there any other way than combining the two lists and making a composite list OR by modifying the DefaultListModel 除了组合两个列表并制作复合列表或修改DefaultListModel之外,还有其他方法吗?

Encapsulate the String (or better File ) and InetAddress into a single object and show those objects in one JList using an appropriate renderer. String (或更好的File )和InetAddress封装到单个对象中,并使用适当的渲染器在一个 JList显示这些对象。

For more information see How to Use Lists & particularly Writing a Custom Cell Renderer . 有关更多信息,请参阅如何使用列表以及特别是编写自定义单元格渲染器

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

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