开发者

JOptionPane or better solution

开发者 https://www.devze.com 2023-04-06 09:19 出处:网络
I would ask something about my project. I have a Java program that connects to a website through a Connection class that takes as parameter an int. This class has only a method that return an ArrayLis

I would ask something about my project. I have a Java program that connects to a website through a Connection class that takes as parameter an int. This class has only a method that return an ArrayList (it gets informations from a web page , and puts results in an arraylist).

In the Main I have a for loop:

for(int i=0;i<insertUserNumber; i++){} 

Inside this loop I invoke a Connection object that gets as parameter the "i" of loop and when the object returns the ArrayList, I take it, do something with it and show the result inside a JOptionPane.

The problem is that ONLY when i click on OK i see the other JOptionPane with the result of operation did in the loop. I wish to see them at the same time so I could see all data.

From Javadoc

All dialogs are modal. Each showXxxDialog method blocks the caller until the user's interaction is complete.

So how can I resolve the problem?

1)Is using multithreading a good solut开发者_开发知识库ion or there are better ones ?

2) is there a way where I can refresh automatically data of the JoptionPane without start the program?

Thanks and sorry for my bad english.


is there a way where I can refresh automatically data of the JoptionPane without start the program?

Certainly. Show a JPanel in it that uses a CardLayout, as shown here.


For which concern the first part of the question:

you can't show multiple JDialog if you use showXXXDialog method, because they are modal. On the other hand if you create a JDialog object you can show it as much as you want:

JDialog first = new JDialog();
first.setSize(new Dimension(80,80));
JDialog second = new JDialog();
second.setSize(new Dimension(80,80));

first.setVisible(true);
second.setVisible(true);

For what concern changing dynamically the data displayed inside the dialog, yes it's also possible. The first parameter of all showXXXDialog methods is a frame (thus can be a JDialog object too). You can do something like:

JDialog dialog = new JDialog();
JPanel p = new JPanel ();
p.setLayout(new FlowLayout());
JLabel label = new JLabel("FOO");
p.add(label);
dialog.add(p);

JOptionPane.showXXXDialog(dialog,....);

If you change the content of JLabel label everywhere else inside your program, your dialog will be automatically updated.

0

精彩评论

暂无评论...
验证码 换一张
取 消