【发布时间】:2020-03-31 03:12:06
【问题描述】:
我正在尝试使用 Jframe 在窗口应用程序中显示客户端详细信息。一切都很好,只是客户端需要等到进程完成才能在 window(Jframe) 中显示结果。
有没有办法在设置Jframe.setVisible(true)后动态显示结果(Jpanel.add());
注意:我是此代码的新手
我试过的代码:
JFrame frame = new JFrame();
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}});
JPanel panel = new JPanel();
frame.setVisible(true);
int y=100;
for (int i = 0; i < 10; i++) {
//connecting DB and fetching data #single loop may take 5 secs to complete the process
panel.add(new JLabel("Client"+i)).setBounds(50,y, 100, 30); //after added, this should display in opened window
y=y+20;
//connecting DB and fetching data
for(int clinetDetails=0;clinetDetails< 3;clinetDetails++) {
panel.add(new JLabel("ClientDetails"+clinetDetails)).setBounds(50,y, 100, 30);
y=y+20;
}
panel.add(new JLabel("Client :"+i+" Completed")).setBounds(50,y, 100, 30);
y=y+20;
// frame.pack();
}
panel.setLayout(new GridLayout(0, 1));
JScrollPane scrollPane = new JScrollPane(panel);
frame.getContentPane().setLayout(new BorderLayout());
frame.getContentPane().add(scrollPane, BorderLayout.CENTER);
frame.setPreferredSize(new Dimension(300, 300));
frame.pack();
【问题讨论】:
-
您在等待时要显示什么?为什么是网格布局?
-
client1 详细信息应显示,直到在循环中处理 client2 详细信息。同样每个客户的详细信息要一一显示