Bonjour

Je vous expose mon problème

J'ai un jpanel integré dans un JScrollPane où j'affiche des images
J'ai besoin de spécifier une largeur fixe avec une hauteur variable selon le nombre d'images affichées

Comment faire cela ?

Pour l'instant je suis obligé d'afficher une hauteur fixe pour que cela fonctionne

Voici le 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
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
 
JPanel PAN_Colonne1 = new JPanel();
        PAN_Colonne1.setPreferredSize(new Dimension(
               (int) ((Informations.screenWidth - 30) * 0.65),
                1800));
        PAN_Colonne1.setBorder(BorderFactory.createLineBorder(Color.black, 5));
        PAN_Colonne1.setBackground(new Color(239, 228, 176));
        PAN_Colonne1.setLayout(new FlowLayout(FlowLayout.LEFT, 15, 15));
 
        JScrollPane scroll = new JScrollPane(PAN_Colonne1,
                ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
                ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
        scroll.setPreferredSize(new Dimension(
                (int) ((Informations.screenWidth - 30) * 0.65),
                (int) ((Informations.screenHeight - 30) * 0.8)));
        container.add(scroll);
 
        //Recuperation de la liste des fichiers
        String[] liste = ManagerPath.getListFichier();
        //Boucle recuperation + vignette
        for (int i = 0; i < liste.length; i++)
        {
            //Path image
            String pathImage = ManagerPath.getNomDossier(liste[i]) + "/1.png";
            //Date et Heure
            String formatDate = "dd/MM/yyyy"; SimpleDateFormat formaterDate = new SimpleDateFormat(formatDate);
            String formatHeure = "HH:mm"; SimpleDateFormat formaterHeure = new SimpleDateFormat(formatHeure);
            String date = formaterDate.format(new Date(new File(liste[i]).lastModified()));
            String heure = formaterHeure.format(new Date(new File(liste[i]).lastModified()));
            //Poids Fichier
            String poidsFichier =  "" + ((float) (new File(liste[i]).length()/1000))/1000 + "Mo";
            //Nom Fichier
            String nomFichier = new File(liste[i]).getName();
 
            ThreadAffichageImage affichageImage = new ThreadAffichageImage(PAN_Colonne1, scroll, pathImage, date, heure,
                    poidsFichier, nomFichier);
            affichageImage.execute();