我正在研究一个显示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.
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(); } }); } }更多推荐
发布评论