IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

AWT/Swing Java Discussion :

JGoodies Form - Supprimer une ligne


Sujet :

AWT/Swing Java

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre régulier
    Profil pro
    Inscrit en
    Juillet 2006
    Messages
    9
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2006
    Messages : 9
    Par défaut JGoodies Form - Supprimer une ligne
    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 !

  2. #2
    Membre averti
    Homme Profil pro
    Inscrit en
    Juillet 2013
    Messages
    24
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Juillet 2013
    Messages : 24
    Par défaut
    Salut,
    Quel est l'erreur que tu as ?

  3. #3
    Membre régulier
    Profil pro
    Inscrit en
    Juillet 2006
    Messages
    9
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2006
    Messages : 9
    Par défaut
    Bonjour, je te remercie de consacrer du temps !

    Je n'avais pas vu ta réponse !

    Mon problème et toujours la je n'ai toujours pas de solution.

    Voici l'erreur :

    Exception in thread "AWT-EventQueue-0" java.lang.IllegalStateException: The removed row 4 must not contain component origins.
    Illegal component=com.jgoodies.forms.factories.DefaultComponentFactory$FormsLabel[,235,86,62x16,alignmentX=0.0,alignmentY=0.0,border=,flags=8388608,maximumSize=,minimumSize=,preferredSize=,defaultIcon=,disabledIcon=,horizontalAlignment=LEADING,horizontalTextPosition=TRAILING,iconTextGap=4,labelFor=javax.swing.JTextField[,297,84,44x20,layout=javax.swing.plaf.basic.BasicTextUI$UpdateHandler,alignmentX=0.0,alignmentY=0.0,border=javax.swing.plaf.BorderUIResource$CompoundBorderUIResource@289ec346,flags=296,maximumSize=,minimumSize=,preferredSize=,caretColor=sun.swing.PrintColorUIResource[r=51,g=51,b=51],disabledTextColor=javax.swing.plaf.ColorUIResource[r=184,g=207,b=229],editable=true,margin=javax.swing.plaf.InsetsUIResource[top=0,left=0,bottom=0,right=0],selectedTextColor=sun.swing.PrintColorUIResource[r=51,g=51,b=51],selectionColor=javax.swing.plaf.ColorUIResource[r=184,g=207,b=229],columns=0,columnWidth=0,command=,horizontalAlignment=LEADING],text=Largeur :,verticalAlignment=CENTER,verticalTextPosition=CENTER]
    at com.jgoodies.forms.layout.FormLayout.shiftComponentsVertically(FormLayout.java:747)
    at com.jgoodies.forms.layout.FormLayout.removeRow(FormLayout.java:696)
    at calculpierre.FenPieces.actionPerformed(FenPieces.java:142)
    at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2022)
    at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2346)
    at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
    at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
    at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252)
    at java.awt.Component.processMouseEvent(Component.java:6525)
    at javax.swing.JComponent.processMouseEvent(JComponent.java:3322)
    at java.awt.Component.processEvent(Component.java:6290)
    at java.awt.Container.processEvent(Container.java:2234)
    at java.awt.Component.dispatchEventImpl(Component.java:4881)
    at java.awt.Container.dispatchEventImpl(Container.java:2292)
    at java.awt.Component.dispatchEvent(Component.java:4703)
    at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4898)
    at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4533)
    at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4462)
    at java.awt.Container.dispatchEventImpl(Container.java:2278)
    at java.awt.Window.dispatchEventImpl(Window.java:2739)
    at java.awt.Component.dispatchEvent(Component.java:4703)
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:751)
    at java.awt.EventQueue.access$500(EventQueue.java:97)
    at java.awt.EventQueue$3.run(EventQueue.java:702)
    at java.awt.EventQueue$3.run(EventQueue.java:696)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:75)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:86)
    at java.awt.EventQueue$4.run(EventQueue.java:724)
    at java.awt.EventQueue$4.run(EventQueue.java:722)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:75)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:721)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)
    Merci pour ton aide !

Discussions similaires

  1. [langage] supprimer une ligne
    Par helene22500 dans le forum Langage
    Réponses: 2
    Dernier message: 25/05/2005, 10h27
  2. [JTable] Supprimer une ligne d'un jtable
    Par Orionmel dans le forum Composants
    Réponses: 5
    Dernier message: 05/11/2004, 22h29
  3. [C#] Comment supprimer une ligne dans DataGrid ?
    Par BAUDIER dans le forum ASP.NET
    Réponses: 2
    Dernier message: 20/07/2004, 16h03
  4. supprimer une ligne avec cle etrangere
    Par BaBas dans le forum Langage SQL
    Réponses: 4
    Dernier message: 15/07/2003, 11h24
  5. Supprimer une ligne dans un fichier
    Par sbeu dans le forum Langage
    Réponses: 3
    Dernier message: 13/05/2003, 10h30

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo