Bonjour
Dans mon application, je veux faire des recherches via le réseau. Pour faire patienter l'utilisateur, je veux lui afficher une boite de dialogue lui indiquant quelques infos sur la recherche. Or à l'utilisation, ma fenêtre de dialogue apparaît bien, mais toute grise !
Or si je met la JDialog en setModal(true), elle apparaît correctement mais bloque tout le processus.
Voici mon code:
Ma boîte de dialogue étant bien entendy Wait Dialog, voici son code:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21WaitDialog wd = new WaitDialog(); wd.setLocationRelativeTo(mw); mw.getGLJPanel().setEnabled(false); int cpt = 1; for (Protein2 p : undefLocations) { wd.updateJLabel("Processing protein "+cpt+" on "+undefLocations.size()); AskWeb aw = new AskWeb(this.organism, this.mapLocations, p); aw.start(); while (aw.isAlive()) { try { Thread.sleep(500); } catch (InterruptedException ie) { ie.printStackTrace(System.err); } } cpt++; } wd.close(); mw.getGLJPanel().setEnabled(true); printLocations();
Merci d'avance à celui qui éclairera ma lanterne.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65 public class WaitDialog extends JDialog { private final String wait = "Please, wait while app is retrieving data"; private final int labelsLimit = 3; private JLabel[] labels = new JLabel[labelsLimit]; private JPanel panel; private final Dimension dim = new Dimension(320, 210); public WaitDialog() { buildComponents(); this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); } private void buildComponents() { panel = new JPanel(new BorderLayout()); panel.setBorder(BorderFactory.createLineBorder(Color.BLACK)); this.getContentPane().add(panel); panel.setBackground(Color.WHITE); try { labels[0] = new JLabel(new ImageIcon(getClass().getResource("waittoplogo.jpg")), JLabel.CENTER); labels[1] = new JLabel(new ImageIcon(getClass().getResource("wait_a.gif")), JLabel.CENTER); labels[2] = new JLabel(wait, JLabel.CENTER); for (int i = 0; i < labelsLimit; i++) { String location = ""; switch (i) { case 0: location = BorderLayout.NORTH; break; case 1: location = BorderLayout.CENTER; break; case 2: location = BorderLayout.SOUTH; break; } panel.add(labels[i], location); } } catch (NullPointerException npe) { JOptionPane.showMessageDialog(null, "Problem with app, exiting", "Error", JOptionPane.ERROR_MESSAGE); System.exit(1); } this.setMinimumSize(dim); this.setPreferredSize(dim); this.setResizable(false); this.setUndecorated(true); this.setAlwaysOnTop(true); this.requestFocus(); this.setVisible(true); } public void close() { this.setVisible(false); this.dispose(); } public void updateJLabel(String s) { System.out.println(s); final int last = this.labelsLimit - 1; labels[last] = new JLabel(s); panel.remove(last); panel.add(labels[last], last); panel.updateUI(); } }
@++






Répondre avec citation



Partager