JOptionPane MessageDialog在java中显示数组的数据(JOptionPane MessageDialog to display data of an array in java

编程入门 行业动态 更新时间:2024-10-23 07:15:08
JOptionPane MessageDialog在java中显示数组的数据(JOptionPane MessageDialog to display data of an array in java)

我正在研究一个显示MessageDialog的程序,该程序显示我创建的数组的数据。 例如,每行:

11327 | 933393 | 2在数组的元素0内。 11833 | 938393 | 1在数组的元素1内。

例如,假设下面的数字在MessageDialog :

11327 | 933393 | 2 11833 | 938393 | 1 11934 | 483393 | 7

我唯一的问题是,我只能按MessageDialog逐个显示数组中的每个元素。 但我想在单个MessageDialog中显示所有3个元素。

任何关于如何在一个MessageDialog中显示整个数组的提示或提示? :)

I'm working on a program that displays a MessageDialog which shows data of an array I created. Each line for example:

11327|933393|2 is inside element 0 of an array. 11833|938393|1 is inside element 1 of an array.

For example pretend the numbers below are inside the MessageDialog:

11327|933393|2 11833|938393|1 11934|483393|7

My only problem is that I can only display each element of the array one by one per MessageDialog. but I want to display all 3 elements inside one single MessageDialog.

Any hints or tips of how I can display my entire array inside one MessageDialog? :)

最满意答案

您可以在对话框中放置任意组件,如本例所示。 JList或JTable似乎是一个不错的选择。

附录:这是一个使用JList的简单示例。

在这里输入图像描述

import java.awt.EventQueue; import javax.swing.JList; import javax.swing.JOptionPane; import javax.swing.JPanel; /** @see https://stackoverflow.com/questions/7781781 */ public class OptionList { private void display() { String[] items = { "11327|933393|2", "11833|938393|1", "11934|483393|7" }; JList list = new JList(items); JPanel panel = new JPanel(); panel.add(list); JOptionPane.showMessageDialog(null, panel); } public static void main(String[] args) { EventQueue.invokeLater(new Runnable() { @Override public void run() { new OptionList().display(); } }); } }

You can place arbitrary components in your dialog, as shown in this example. A JList or JTable would seem to be a good choice.

Addendum: Here's a simple example using JList.

enter image description here

import java.awt.EventQueue; import javax.swing.JList; import javax.swing.JOptionPane; import javax.swing.JPanel; /** @see https://stackoverflow.com/questions/7781781 */ public class OptionList { private void display() { String[] items = { "11327|933393|2", "11833|938393|1", "11934|483393|7" }; JList list = new JList(items); JPanel panel = new JPanel(); panel.add(list); JOptionPane.showMessageDialog(null, panel); } public static void main(String[] args) { EventQueue.invokeLater(new Runnable() { @Override public void run() { new OptionList().display(); } }); } }

更多推荐

本文发布于:2023-07-31 20:57:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1347362.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数组   数据   java   JOptionPane   MessageDialog

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!