Java:在JPanel/JFrame中列出项目的可编辑列表 [英] Java: Making a editable list of items in a JPanel/JFrame

查看:110
本文介绍了Java:在JPanel/JFrame中列出项目的可编辑列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对不起,我是GUI界面的初学者(真的,是Java的初学者),我想知道:如何列出用户可以向其中添加项目或从中删除项目的项目列表,同时按下+或-按钮?

Sorry, I'm kind of a beginner to GUI interfaces (well, a beginner to java, really), and I was wondering: How does one make a list of items that the user can add items to or remove items from, with the press of a + or - button?

我真正想要的(对不起,如果我在这里有点模糊)是您有时在应用程序窗口中看到的那些列表之一,它看起来像一个文本框,但无法键入.现在,我的应用程序(这是一个用于组织医院时间表的小型应用程序)仅从一个文本文件读取并写入另一个文本文件.没有GUI,没有窗口,用户只需在文本文件中写一堆名称(每行一个),然后运行jar并打开输出文件,并且计划就在那儿.我希望他们能够使用按钮从列表中添加或删除名称-通过单击加号"并键入名称来添加名称,然后通过选择名称并单击减号"来删除名称.但是,我仍然希望将其保存到文本文件,以便下次用户打开该应用程序时,所有名称仍在列表中. 为了清楚起见,我不希望有一个列表显示输出(即,将名称组织成一个日程表),而只包含一个包含输入的列表.

What I really want (sorry if I'm being a little vague here) is one of those lists you sometimes see in application windows, which looks like a text box but cannot be typed in. Right now my application (it's a small app to organize the schedule of a hospital) just reads from a text file and writes to another text file. No GUI, no window, the user just writes a bunch of names in the text file, one per line, then runs the jar and opens the output file and the schedule is there. I want them to just be able to add or remove names from a list with buttons — adding a name by clicking 'plus' and typing the name, and removing a name by selecting the name and clicking 'minus'. I still, however, want it to save to a text file, so that the next time the user opens the app, all the names are still on the list. Just to be clear, I don't want a list displaying the output (i.e. the names organized into a schedule), just one containing the input.

非常感谢您可以提供的任何帮助.

Thanks a lot for any help you can give.

推荐答案

您可能希望具有几个JButton实例的JList添加/删除项目.

You probably want a JList with a couple of JButton instances to add/remove items.

请参阅:

  • How to Use Lists
  • How to Use Buttons, Check Boxes, and Radio Buttons

这篇关于Java:在JPanel/JFrame中列出项目的可编辑列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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