简体   繁体   English

如何在JComponent中显示ArrayList项

[英]How to display ArrayList items in a JComponent

I have this: 我有这个:

ArrayList lovely = new ArryList(4);
lovely.add("Tall, Short, Average");         // line 1
lovely.add("mangoes, apples, Bananas");     // line 2
lovely.add("this, that");                   // line 3
lovely.add(“1, 2, 3, 4, 5, 6”)              // line 4

I'd like to have the array list displayed in such a way that each category shows in its own line, like how google list their search results. 我希望以这样的方式显示数组列表,使每个类别显示在自己的行中,就像谷歌列出他们的搜索结果一样。 Does anyone know how to do this? 有谁知道如何做到这一点? I'd like such displayed in a JComponent, but am not sure of which one to use, nor how to do this. 我想在JComponent中显示这样的内容,但不确定要使用哪一个,也不知道如何使用它。 Do JAVA programmers use JTextFields , JTextPanes, or what do they use. JAVA程序员是否使用JTextFields,JTextPanes或他们使用什么。

Help here will be much appreciated. 这里的帮助将不胜感激。

Java programmers use a JList . Java程序员使用JList You can constuct it like this: 你可以像这样构建它:

new JList(lovely.toArray())

It displays each item in a separate line in a list. 它在列表中的单独行中显示每个项目。

You might want to try JLabel or JTextPane because they support simple HTML commands. 您可能想尝试JLabelJTextPane,因为它们支持简单的HTML命令。 It's quite nice if you want to give neat output in a simple manner. 如果你想以简单的方式提供整洁的输出,那就太好了。 Have a look here: http://docs.oracle.com/javase/tutorial/uiswing/components/html.html 看看这里: http//docs.oracle.com/javase/tutorial/uiswing/components/html.html

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

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