Bonsoir à tous,

Je viens vers vous car la après une multitude de recherche je ne trouve pas la solution !


Je développe un programme de calcul de prix de plan de travail en pierre et pour cela sur une partie de la fenêtre il est possible de cliquer sur un bouton pour ajouter des lignes (qui correspondent à un morceau de plan de travail).

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
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package calculpierre;
 
import com.jgoodies.forms.builder.PanelBuilder;
import com.jgoodies.forms.factories.CC;
import com.jgoodies.forms.layout.FormLayout;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.Iterator;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.border.TitledBorder;
 
/**
 *
 * @author Gianni
 */
public class FenPieces implements ActionListener {
 
    FormLayout layout;
 
    JButton boutonAjouter;
    JButton boutonCalculer;
 
    PanelBuilder builder;
 
    JFrame fenPrincipal;
 
    int x;
    int y;
 
    Object[][][] lignes;
 
    double total;
 
    ArrayList<Ligne> list;
 
    public FenPieces(JFrame fenPrincipal) {
 
        this.fenPrincipal = fenPrincipal;
 
        boutonAjouter = new JButton("Ajouter");
        boutonAjouter.addActionListener(this);
 
        boutonCalculer = new JButton("Calculer");
        boutonCalculer.addActionListener(this);
 
        x = 1;
        y = 1;
 
        total = 0.0;
 
        list = new ArrayList<Ligne>();
    }
 
    JPanel panel() {
        JPanel panel = new JPanel(new FlowLayout(0, 10, 10));
 
        String colonnes = "40dlu, 25dlu, 15dlu, C:20dlu, 35dlu, 25dlu, 15dlu, C:20dlu, 25dlu, 15dlu";
        String lignes = "pref, pref, pref, pref, pref, pref, pref, pref, pref, pref, pref, pref, pref, pref,pref, pref, pref, pref, pref, pref, pref, pref, pref, pref, pref, pref, pref, pref";
 
        layout = new FormLayout(colonnes, lignes);
        builder = new PanelBuilder(layout);
 
        builder.add(this.boutonAjouter, CC.xyw(x, y, 4));
        builder.add(this.boutonCalculer, CC.xyw(x + 5, y, 5));
        y++;
 
        builder.getPanel().setBorder(new TitledBorder("Pièces"));
 
        panel.add(builder.getPanel());
        return panel;
    }
 
    @Override
    public void actionPerformed(ActionEvent ae) {
        Object source = ae.getSource();
 
        if (source == boutonAjouter) {
 
            Ligne ligne = new Ligne();
            list.add(ligne);
 
            builder.addLabel("Longueur :", CC.xy(x, y));
            builder.add(ligne.getLongueurJTF(), CC.xy(x + 1, y));
            builder.addLabel("mm", CC.xy(x + 2, y));
 
            builder.addLabel("X", CC.xy(x + 3, y));
 
            builder.addLabel("Largeur :", CC.xy(x + 4, y));
            builder.add(ligne.getLargeurJTF(), CC.xy(x + 5, y));
            builder.addLabel("mm", CC.xy(x + 6, y));
 
            builder.addLabel("=", CC.xy(x + 7, y));
 
            builder.add(ligne.getMetreCarreJTF(), CC.xy(x + 8, y));
            builder.addLabel("m²", CC.xy(x + 9, y));
 
            y++;
            fenPrincipal.revalidate();
        }
 
        if (source == boutonCalculer) {
            calculTotal();
        }
 
    }
 
    private void calculTotal() {
 
        total = 0.0;
        Iterator<Ligne> it = list.iterator();
 
        while (it.hasNext()) {
            Ligne ligne = it.next();
            if (!ligne.getMetreCarreJTF().getText().equals("")) {
                total += Double.valueOf(ligne.getMetreCarreJTF().getText());
            }
        }
 
        System.out.println(layout.getRowCount());
 
 
        //layout.removeRow(1);
 
        System.out.println("Total : " + total);
    }
}
Ce que je souhaiterais c'est de rajouter un bouton - en début de chaque ligne afin de pouvoir la supprimer.

Cependant après test de layout.removeRow(1); j'obtiens une erreur.

Merci à tous pour votre aide !