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

SWT/JFace Java Discussion :

[SWT] Expand Bar en cascade


Sujet :

SWT/JFace Java

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre à l'essai
    Inscrit en
    Novembre 2007
    Messages
    5
    Détails du profil
    Informations forums :
    Inscription : Novembre 2007
    Messages : 5
    Par défaut [SWT] Expand Bar en cascade
    Bonjour,

    J'aimerai faire en sorte que l'un de mes éléments dans un ExpandItem soit une ExpandBar (à la manière d'un Tree).

    L'objectif est en fait d'insérer des widgets dans mon arborescence pour une modification directe de paramètres.

    Voici le code que j'ai pour le moment (extrait en grande partie des exemples fournis par la doc Eclipse de SWT):
    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
     
    ExpandBar bar = new ExpandBar (shell, SWT.V_SCROLL);
    composite = new Composite (bar, SWT.NONE);
    layout = new GridLayout (2, false);
    layout.marginLeft = layout.marginTop = layout.marginRight =
    layout.marginBottom = 10;
    layout.verticalSpacing = 10;
    composite.setLayout(layout);    
     
    //Test D'ajout d'une ExpandBar
    GridData expSec = new GridData();
    expSec.horizontalSpan = 2;
    expSec.grabExcessVerticalSpace = true;
    ExpandBar barSec = new ExpandBar(composite, SWT.NONE);
    Composite compoSec = new Composite(barSec, SWT.NONE);
    GridLayout laySec = new GridLayout(2, true);
    compoSec.setLayout(laySec);
    ExpandItem itemSec = new ExpandItem(barSec, SWT.NONE, 0);
    itemSec.setText("TRIGGER");
    itemSec.setHeight(compoSec.computeSize(SWT.DEFAULT, SWT.DEFAULT).y);
    itemSec.setControl(compoSec);
    barSec.setLayoutData(expSec);
     
    //Fin d'implémentation du test d'ajout
    A l'affichage, j'ai bien la "sous-barre" qui s'affiche, mais pas son contenu au déroulement de cette dernière.

    Ma question est donc: est-il possible de créer une "sous-barre" de type sous-menu dans un objet ExpandBar? Si oui, par quels moyens puis-je y arriver?

    Merci à tous et bonne journée

    Abdehüe

  2. #2
    Membre à l'essai
    Inscrit en
    Novembre 2007
    Messages
    5
    Détails du profil
    Informations forums :
    Inscription : Novembre 2007
    Messages : 5
    Par défaut
    Autant pour moi, le code collé correspondait à un divers essai!!

    Voici le nouveau code (pour la deuxiième partie) comportant des widgets dans la "sous-barre":
    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
     
     
    //Test D'ajout d'une ExpandBar
            GridData expSec = new GridData();
            expSec.horizontalSpan = 2;
            expSec.grabExcessVerticalSpace = true;
            ExpandBar barSec = new ExpandBar(composite, SWT.NONE);
            Composite compoSec = new Composite(barSec, SWT.NONE);
            GridLayout laySec = new GridLayout(2, true);
    //        laySec.marginLeft = 20;
    //        laySec.marginTop = laySec.marginRight = laySec.marginBottom = 10;
    //        laySec.verticalSpacing = 10;
            compoSec.setLayout(laySec);
            label = new Label (compoSec, SWT.NONE);
            label.setImage(display.getSystemImage(SWT.ICON_WARNING));
            label = new Label (compoSec, SWT.NONE);
            label.setText("SWT.ICON_WARNING");
            label = new Label (compoSec, SWT.NONE);
            label.setImage(display.getSystemImage(SWT.ICON_QUESTION));
            label = new Label (compoSec, SWT.NONE);
            label.setText("SWT.ICON_QUESTION");
            ExpandItem itemSec = new ExpandItem(barSec, SWT.NONE, 0);
            itemSec.setText("TRIGGER");
            itemSec.setHeight(compoSec.computeSize(SWT.DEFAULT,
                    SWT.DEFAULT).y);
            itemSec.setControl(compoSec);
            barSec.setLayoutData(expSec);
            //Fin d'implémentation du test

  3. #3
    Membre expérimenté

    Profil pro
    Inscrit en
    Août 2006
    Messages
    218
    Détails du profil
    Informations personnelles :
    Âge : 50
    Localisation : France, Rhône (Rhône Alpes)

    Informations forums :
    Inscription : Août 2006
    Messages : 218
    Par défaut
    Voici un exemple, est-ce bien ce que tu as en tête ?

    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
     
    import org.eclipse.swt.SWT;
    import org.eclipse.swt.layout.FillLayout;
    import org.eclipse.swt.layout.GridData;
    import org.eclipse.swt.layout.GridLayout;
    import org.eclipse.swt.widgets.Composite;
    import org.eclipse.swt.widgets.Display;
    import org.eclipse.swt.widgets.ExpandBar;
    import org.eclipse.swt.widgets.ExpandItem;
    import org.eclipse.swt.widgets.Label;
    import org.eclipse.swt.widgets.Shell;
     
    public class Test {
        public static void main(String[] args) {
            Display display = new Display();
            Shell shell = new Shell(display);
            shell.setLayout(new FillLayout());
     
            // Création de l'ExpandBar
            final ExpandBar expandBarrePrincipale = new ExpandBar(shell, SWT.NONE);
     
            // Créé un composite qui sera stocké dans l'expandBar
            final Composite compositePrincipal = new Composite(expandBarrePrincipale, SWT.NONE);
            GridLayout layoutPrincipal = new GridLayout(2, true);
            compositePrincipal.setLayout(layoutPrincipal);
            Label label = new Label(compositePrincipal, SWT.NONE);
            label.setImage(display.getSystemImage(SWT.ICON_WARNING));
            label = new Label(compositePrincipal, SWT.NONE);
            label.setText("SWT.ICON_WARNING");
     
            label = new Label(compositePrincipal, SWT.NONE);
            label.setImage(display.getSystemImage(SWT.ICON_QUESTION));
            label = new Label(compositePrincipal, SWT.NONE);
            label.setText("SWT.ICON_QUESTION");
     
            final ExpandItem itemPrincipal = new ExpandItem(expandBarrePrincipale, SWT.NONE, 0);
            itemPrincipal.setText("TRIGGER");
            itemPrincipal.setHeight(compositePrincipal.computeSize(SWT.DEFAULT, SWT.DEFAULT).y);
            itemPrincipal.setControl(compositePrincipal);
     
            /**
             * ExpandBar secondaire
             */
            final ExpandBar expandBarreSecondaire = new ExpandBar(compositePrincipal, SWT.NONE);
            expandBarreSecondaire.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, true, 2, 1));
     
            final Composite compositeSecondaire = new Composite(expandBarreSecondaire, SWT.NONE);
            compositeSecondaire.setLayout(new GridLayout(2, true));
     
            Label labelSec = new Label(compositeSecondaire, SWT.NONE);
            labelSec.setImage(display.getSystemImage(SWT.ICON_INFORMATION));
            labelSec = new Label(compositeSecondaire, SWT.NONE);
            labelSec.setText("SWT.ICON_INFORMATION");
     
            final ExpandItem itemSecondaire = new ExpandItem(expandBarreSecondaire, SWT.NONE, 0);
            itemSecondaire.setText("TRIGGER 2(le retour)");
            itemSecondaire.setHeight(compositeSecondaire.computeSize(SWT.DEFAULT, SWT.DEFAULT).y);
            itemSecondaire.setControl(compositeSecondaire);
     
            /**
             * Fin ExpandBar secondaire
             */
     
            itemPrincipal.setHeight(compositePrincipal.computeSize(SWT.DEFAULT, SWT.DEFAULT).y + compositeSecondaire.computeSize(SWT.DEFAULT, SWT.DEFAULT).y);
     
     
            // Fin d'implémentation du test
     
            shell.open();
            while (!shell.isDisposed()) {
                if (!display.readAndDispatch())
                    display.sleep();
            }
            display.dispose();
        }
    }

    Laurent

  4. #4
    Membre à l'essai
    Inscrit en
    Novembre 2007
    Messages
    5
    Détails du profil
    Informations forums :
    Inscription : Novembre 2007
    Messages : 5
    Par défaut
    C'est exactement ce que je cherchais!!

    La clé je pense se trouve dans le paramétrage de la taille de mon onglet principal:

    itemPrincipal.setHeight(compositePrincipal.computeSize(SWT.DEFAULT, SWT.DEFAULT).y + compositeSecondaire.computeSize(SWT.DEFAULT, SWT.DEFAULT).y);

    Je n'avais pas pensé à sommer les deux (malgré que maintenant ça me paraisse évident )

    Un grand merci à toi...

    A bientôt

    Abdehüe

  5. #5
    Membre à l'essai
    Inscrit en
    Novembre 2007
    Messages
    5
    Détails du profil
    Informations forums :
    Inscription : Novembre 2007
    Messages : 5
    Par défaut
    Alors, après test il réside encore un problème!!

    La solution garde pour un onglet déroulant une taille fixe. Ceci pose un problème lorsque l'onglet n'est pas placé en fin de liste. Pour donner un exemple plus parlant, j'ai modifié un peu ton code ce qui illustre le problème:
    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
     
    import org.eclipse.swt.*;
     
    public class Main {
        public static void main(String[] args) {
            Display display = new Display();
            Shell shell = new Shell(display);
            shell.setLayout(new FillLayout());
     
            // Création de l'ExpandBar
            final ExpandBar expandBarrePrincipale = new ExpandBar(shell, SWT.NONE);
     
            // Créé un composite qui sera stocké dans l'expandBar
            final Composite compositePrincipal = new Composite(expandBarrePrincipale, SWT.NONE);
            GridLayout layoutPrincipal = new GridLayout(2, true);
            compositePrincipal.setLayout(layoutPrincipal);
            Label label = new Label(compositePrincipal, SWT.NONE);
            label.setImage(display.getSystemImage(SWT.ICON_WARNING));
            label = new Label(compositePrincipal, SWT.NONE);
            label.setText("SWT.ICON_WARNING");
            /**
             * ExpandBar secondaire
             */
            final ExpandBar expandBarreSecondaire = new ExpandBar(compositePrincipal, SWT.NONE);
            expandBarreSecondaire.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, true, 2, 1));
     
            final Composite compositeSecondaire = new Composite(expandBarreSecondaire, SWT.NONE);
            compositeSecondaire.setLayout(new GridLayout(2, true));
     
            Label labelSec = new Label(compositeSecondaire, SWT.NONE);
            labelSec.setImage(display.getSystemImage(SWT.ICON_INFORMATION));
            labelSec = new Label(compositeSecondaire, SWT.NONE);
            labelSec.setText("SWT.ICON_INFORMATION");
     
            final ExpandItem itemPrincipal = new ExpandItem(expandBarrePrincipale, SWT.NONE, 0);
            itemPrincipal.setText("TRIGGER");
            itemPrincipal.setHeight(compositePrincipal.computeSize(SWT.DEFAULT, SWT.DEFAULT).y);
            itemPrincipal.setControl(compositePrincipal);
     
     
            final ExpandItem itemSecondaire = new ExpandItem(expandBarreSecondaire, SWT.NONE, 0);
            itemSecondaire.setText("TRIGGER 2(le retour)");
            itemSecondaire.setHeight(compositeSecondaire.computeSize(SWT.DEFAULT, SWT.DEFAULT).y);
            itemSecondaire.setControl(compositeSecondaire);
     
            /**
             * Fin ExpandBar secondaire
             */
            label = new Label(compositePrincipal, SWT.NONE);
            label.setImage(display.getSystemImage(SWT.ICON_QUESTION));
            label = new Label(compositePrincipal, SWT.NONE);
            label.setText("SWT.ICON_QUESTION");
     
     
    //        /**
    //         * ExpandBar secondaire
    //         */
    //        final ExpandBar expandBarreSecondaire = new ExpandBar(compositePrincipal, SWT.NONE);
    //        expandBarreSecondaire.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, true, 2, 1));
    // 
    //        final Composite compositeSecondaire = new Composite(expandBarreSecondaire, SWT.NONE);
    //        compositeSecondaire.setLayout(new GridLayout(2, true));
    // 
    //        Label labelSec = new Label(compositeSecondaire, SWT.NONE);
    //        labelSec.setImage(display.getSystemImage(SWT.ICON_INFORMATION));
    //        labelSec = new Label(compositeSecondaire, SWT.NONE);
    //        labelSec.setText("SWT.ICON_INFORMATION");
    // 
    //        final ExpandItem itemSecondaire = new ExpandItem(expandBarreSecondaire, SWT.NONE, 0);
    //        itemSecondaire.setText("TRIGGER 2(le retour)");
    //        itemSecondaire.setHeight(compositeSecondaire.computeSize(SWT.DEFAULT, SWT.DEFAULT).y);
    //        itemSecondaire.setControl(compositeSecondaire);
    // 
    //        /**
    //         * Fin ExpandBar secondaire
    //         */
     
            itemPrincipal.setHeight(compositePrincipal.computeSize(SWT.DEFAULT, SWT.DEFAULT).y + compositeSecondaire.computeSize(SWT.DEFAULT, SWT.DEFAULT).y);
     
     
            // Fin d'implémentation du test
     
            shell.open();
            while (!shell.isDisposed()) {
                if (!display.readAndDispatch())
                    display.sleep();
            }
            display.dispose();
        }
    }
    Ainsi, il y aurait-il moyen de définir pour un item principal une taille dynamique dépendant de la taille variable de mon ExpandItem secondaire?

    Merci à vous

    Abdehüe

  6. #6
    Membre à l'essai
    Inscrit en
    Novembre 2007
    Messages
    5
    Détails du profil
    Informations forums :
    Inscription : Novembre 2007
    Messages : 5
    Par défaut
    Et bien, il semblerait que j'ai trouvé la réponse (voir code joint). Ce n'est pas très joli, donc si vous connaissez de meilleurs moyens, je suis preneur.

    cependant, la solution tourne...
    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
     
    public class Main {
        public static void main(String[] args) {
            Display display = new Display();
            Shell shell = new Shell(display);
            shell.setLayout(new FillLayout());
     
            // Création de l'ExpandBar
            final ExpandBar expandBarrePrincipale = new ExpandBar(shell, SWT.NONE);
     
            // Créé un composite qui sera stocké dans l'expandBar
            final Composite compositePrincipal = new Composite(expandBarrePrincipale, SWT.NONE);
            GridLayout layoutPrincipal = new GridLayout(2, true);
            compositePrincipal.setLayout(layoutPrincipal);
            Label label = new Label(compositePrincipal, SWT.NONE);
            label.setImage(display.getSystemImage(SWT.ICON_WARNING));
            label = new Label(compositePrincipal, SWT.NONE);
            label.setText("SWT.ICON_WARNING");
            /**
             * ExpandBar secondaire
             */
            final ExpandBar expandBarreSecondaire = new ExpandBar(compositePrincipal, SWT.NONE);
            expandBarreSecondaire.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, true, 2, 1));
     
            final Composite compositeSecondaire = new Composite(expandBarreSecondaire, SWT.NONE);
            compositeSecondaire.setLayout(new GridLayout(2, true));
     
            Label labelSec = new Label(compositeSecondaire, SWT.NONE);
            labelSec.setImage(display.getSystemImage(SWT.ICON_INFORMATION));
            labelSec = new Label(compositeSecondaire, SWT.NONE);
            labelSec.setText("SWT.ICON_INFORMATION");
     
            final ExpandItem itemPrincipal = new ExpandItem(expandBarrePrincipale, SWT.NONE, 0);
            itemPrincipal.setText("TRIGGER");
            itemPrincipal.setControl(compositePrincipal);
     
     
            final ExpandItem itemSecondaire = new ExpandItem(expandBarreSecondaire, SWT.NONE, 0);
            itemSecondaire.setText("TRIGGER 2(le retour)");
            itemSecondaire.setHeight(compositeSecondaire.computeSize(SWT.DEFAULT, SWT.DEFAULT).y);
            itemSecondaire.setControl(compositeSecondaire);
     
     
            /**
             * Fin ExpandBar secondaire
             */
            label = new Label(compositePrincipal, SWT.NONE);
            label.setImage(display.getSystemImage(SWT.ICON_QUESTION));
            label = new Label(compositePrincipal, SWT.NONE);
            label.setText("SWT.ICON_QUESTION");
     
            final int Tprincipal = compositePrincipal.computeSize(SWT.DEFAULT, SWT.DEFAULT).y;
            itemPrincipal.setHeight(Tprincipal);
            expandBarreSecondaire.addExpandListener(new ExpandListener() {
                   public void itemCollapsed(ExpandEvent event) {
                       System.out.println(event.item);
                       System.out.println("avant retour à la normale, Taille = " + Tprincipal);
                       itemPrincipal.setHeight(Tprincipal);
                       System.out.println("aprèsretour à la normale");
     
                   }
                   public void itemExpanded(ExpandEvent event){
                       System.out.println(event.item);
                       itemPrincipal.setHeight(compositePrincipal.computeSize(SWT.DEFAULT, SWT.DEFAULT).y + compositeSecondaire.computeSize(SWT.DEFAULT, SWT.DEFAULT).y);
                   }
                });
     
            // Fin d'implémentation du test
     
            shell.open();
            while (!shell.isDisposed()) {
                if (!display.readAndDispatch())
                    display.sleep();
            }
            display.dispose();
        }
    }

    Merci encore pour votre aide.

    Abdehüe

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. [swt]expand event et treeviewer
    Par Fabien[ALT] dans le forum SWT/JFace
    Réponses: 1
    Dernier message: 27/06/2009, 19h05
  2. SWT Menus en cascade et sélection des MenuItem
    Par Cluster37 dans le forum SWT/JFace
    Réponses: 2
    Dernier message: 12/11/2008, 09h09
  3. [SWT] Problème de paramètre GridData
    Par yolepro dans le forum SWT/JFace
    Réponses: 4
    Dernier message: 06/12/2002, 10h37
  4. [SWT] Un bon coin ou trouver des infos pratik
    Par yolepro dans le forum SWT/JFace
    Réponses: 8
    Dernier message: 04/12/2002, 14h08
  5. outlook bar
    Par camis dans le forum Composants VCL
    Réponses: 3
    Dernier message: 13/08/2002, 17h13

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