简体   繁体   English

如何将元素从Jlist_1添加/删除到Jlist_2(Java netbeans)

[英]How can I add/remove Elements from Jlist_1 to Jlist_2 (Java netbeans)

Java Jlist图片

I want add element to Selected Subject List from Total Subjects List and want remove the element which was add in Selected Subject List from Total Subjects List 我想将元素添加到“总主题列表”中的“选定主题列表”中,并要删除从“总主题列表”中添加到“选定主题列表”中的元素

I am using netbeans.(Java Application) 我正在使用netbeans。(Java应用程序)

Please anybody help to solve this problem. 请任何人帮助解决此问题。

Thank you 谢谢

Read the section from the Swing tutorial on How to Use Lists . 阅读Swing教程中有关如何使用列表的部分

The "Hire/File" demo shows how you can remove an item from the DefaultListModel and how you can add an item to the DefaultListModel. “租户/文件”演示演示了如何从DefaultListModel中删除项目以及如何向DefaultListModel中添加项目。

So you combine the logic of those two events and put the code into the ActionListener of you button and you have your solution. 因此,您将这两个事件的逻辑结合在一起,并将代码放入按钮的ActionListener中,便有了解决方案。

The main difference in your code is that instead of getting the item to add from the text field you get the "selected item" from the JList. 您的代码的主要区别在于,不是从文本字段中获取要添加的项目,而是从JList获取“选定的项目”。

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

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