In Java SWT, i am trying to display few information in a seperate console. Is it possible to display list of items to be displayed in the console?

huangapple go评论51阅读模式
英文:

In Java SWT, i am trying to display few information in a seperate console. Is it possible to display list of items to be displayed in the console?

问题

propertyConsole.setText("\n 项目名称:" + item1.projectName + ".act"

  • " " + "\n\n 分类: " + item1.category + " "
  • "\n\n 模块: " + item1.modulesList[]);

在Java SWT中,我尝试在一个单独的控制台中显示一些信息。是否可以在控制台中显示要显示的项目列表?modulesList实际上是一个包含4或5个项目的列表,需要显示在控制台中。

英文:
propertyConsole.setText("\n	Project Name:" + item1.projectName + ".act"
									+ "	" + "\n\n	Category:		" + item1.category + "	"
									+ "\n\n	Modules:		       " + item1.modulesList[]); 

In Java SWT, i am trying to display few information in a seperate console. Is it possible to display list of items to be displayed in the console? The modulesList is actually a list of 4 or 5 items which need to be displayed in the console

答案1

得分: 1

您可以使用 Arrays#toString 方法来返回给定数组的 String 表示。

这是一个示例。

String[] strings = { "abc", "def", "ghi" };
System.out.println(Arrays.toString(strings));

输出

[abc, def, ghi]

此外,您可以使用 StringBuilderFormatter 类来组织您的 String 值,可能会很有用。

另外,Formatter 类的 JavaDoc 提供了广泛的格式说明符集合。
Formatter (Java SE 20 & JDK 20) – Conversions

StringBuilder string = new StringBuilder();
Formatter formatter = new Formatter(string);
formatter.format("Project Name: %s.act%n", item1.projectName);
formatter.format("Category:     %s%n", item1.category);
formatter.format("Modules:      %s", Arrays.toString(item1.modulesList));
formatter.flush();
propertyConsole.setText(string.toString());
英文:

You can use the Arrays#toString method to return a String representation of a given array.

Here is an example.

String[] strings = { "abc", "def", "ghi" };
System.out.println(Arrays.toString(strings));

Output

[abc, def, ghi]

Furthermore, you may find it useful to organize your String value by utilizing the StringBuilder and Formatter classes.

Additionally, the Formatter class JavaDoc provides the extensive set of format specifiers.
Formatter (Java SE 20 & JDK 20) – Conversions.

StringBuilder string = new StringBuilder();
Formatter formatter = new Formatter(string);
formatter.format("Project Name: %s.act%n", item1.projectName);
formatter.format("Category:     %s%n", item1.category);
formatter.format("Modules:      %s", Arrays.toString(item1.modulesList));
formatter.flush();
propertyConsole.setText(string.toString());

huangapple
  • 本文由 发表于 2023年6月15日 10:57:15
  • 转载请务必保留本文链接:https://go.coder-hub.com/76478789.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定