Bonjour,

J'ai écrit un programme pour trier des pdf selon leur nombre de pages, en les classant dans de nouveaux dossiers jusqu'à atteindre un total de pages prédéfini. (ça peut paraître idiot mais c'est pour simplifier l'utilisation d'un logiciel d'OCR)

J'ai un interface utilisateur minimal: une première fenêtre qui demande à l'utilisateur le nombre de pages total qu'il désire par dossier, puis je vide ma fenêtre, y ajoute un JTextArea qui contiendra le log et la rajuste au contenu.
Je complète ensuite mon log depuis d'autres classes en appelant:

Code : Sélectionner tout - Visualiser dans une fenêtre à part
UserInterface.updateProcessingInformation("message");
Alors mon programme fonctionne à merveille, sauf au niveau de l'interface graphique, qui ne se met pas à jour correctement.
Voici ma classe UserInterface:

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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package ocr_angel;
 
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
/**
 *
 * @author Titelouve
 */
public class UserInterface {
 
    static JFrame frame = new JFrame("OCR Angel");
    static Container windowContent = new Container();
    static GridBagLayout disposition = new GridBagLayout();
    static GridBagConstraints contr = new GridBagConstraints();
    //First window content
    static JLabel pageLimitLabel = new JLabel("Enter the maximal amount of pages per subfolder :");
    static JTextField pageLimitField = new JTextField(7);
    static JButton enter = new JButton("Run");
    //Second window content
    static JTextArea processingInformation = new JTextArea("");
 
 
    public UserInterface(){
        enter.addActionListener(new EnterActionListener());
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        windowContent = frame.getContentPane();
        askForPageLimit();
    }
 
//USER INTERFACE PART
    public static void askForPageLimit(){
        windowContent.removeAll();
        windowContent.setLayout(disposition);
        addComponent(pageLimitLabel, 0, 0, 1, 1, new Insets(20, 10, 10, 0), GridBagConstraints.HORIZONTAL, GridBagConstraints.WEST);
        addComponent(pageLimitField, 1, 0, 1, 1, new Insets(20, 10, 10, 10), GridBagConstraints.HORIZONTAL, GridBagConstraints.WEST);
        addComponent(enter, 0, 1, 1, 2, new Insets(10, 10, 20, 10), GridBagConstraints.NONE, GridBagConstraints.CENTER);
        frame.setResizable(false);
        frame.pack();
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
    }
 
    public static void showProcessingInformation(){
        windowContent.removeAll();
        windowContent.setLayout(disposition);
        processingInformation.setEditable(false);
        addComponent(processingInformation, 0, 0, 1, 1, new Insets(20, 20, 20, 20), GridBagConstraints.HORIZONTAL, GridBagConstraints.CENTER);
        frame.setResizable(false);
        frame.pack();
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
    }
 
    public static void updateProcessingInformation(String news){
        processingInformation.setText(processingInformation.getText()+news+"   \n   ");
        frame.pack();
        frame.repaint();
    }
 
    static void addComponent(Component item, int column, int line, int height, int width, Insets ins, int  fill, int anchor){
		contr.gridx = column;
		contr.gridy = line;
		contr.gridwidth = width;
		contr.gridheight = height;
		contr.insets = ins;
                contr.fill = fill;
                contr.anchor = anchor;
		disposition.setConstraints(item, contr);
		windowContent.add(item);
    }
 
//IMPLICATION OF CLICKING THE "Enter" BUTTON
    static class EnterActionListener implements ActionListener {
        public void actionPerformed(ActionEvent event) {
            int pl = -1;
            try{
                pl = Integer.parseInt(UserInterface.pageLimitField.getText());
            }catch(Exception e){
            }
            if(pl > 0 && pl < 9999){
                UserInterface.showProcessingInformation();
                new PdfSorter(pl);
            }else{
                UserInterface.askForPageLimit();
            }
        }
    }
}
Donc mon programme lance le main, qui crée un objet UserInterface. Quand l'utilisateur entre une limite de page valide et appuie sur le bouton, je modifie l'interface utilisateur puis crée un objet PdfSorter, qui va trier mes pdfs. A la fin de son tri, PdfSorter crée un objet Log, qui enregistre tous les détails dans un fichier excel.
J'ai fait le choix de créer différentes classes pour rendre mon programme plus compréhensible, et mieux différencier ses étapes.

Dans la pratique, le bug arrive avec le premier changement d'interface, qui ne s'effectue pas correctement. Ma fenêtre s'agrandit bien quand je l'ajuste à mon JTextArea, mais l'intérieur reste noir. Elle n'apparaît correctement que quand tout est fini (pas très utile pour tenir l'utilisateur au courant de ce qui se passe... )

Est-ce qu'il y a un moyen de régler ça sans balancer tout mon code dans une seule classe (ce que je trouve un peu indigeste...)?
Merci d'avance de vos conseils...