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

Interfaces Graphiques en Java Discussion :

jscrollbar dans un jpanel dans un jsplitpane


Sujet :

Interfaces Graphiques en Java

  1. #1
    Membre averti
    Profil pro
    Inscrit en
    Mars 2007
    Messages
    21
    Détails du profil
    Informations personnelles :
    Âge : 41
    Localisation : France

    Informations forums :
    Inscription : Mars 2007
    Messages : 21
    Par défaut jscrollbar dans un jpanel dans un jsplitpane
    Bonjour, voilà j'ai un petit soucis, je repousse le problème, mais y a bien un moment où il va falloir que j'y fasse face :/
    Donc j'ai une frame avec un jsplitpane en composant principale, dans ce jsplitpane, à droite j'ai un jlabel qui contient un GLCanvas et à gauche un jpanel qui contient une série de jbutton, jtogglebutton et jlabel, organisés sur 4 colonnes et 13 lignes avec un gridbaglayout.
    Donc forcément ça prend de la place, et quand je réduis la fenêtre (veticalement, horizontalement j'ai pas de problèmes), les composants du jpanel se superposent et ça ressemble plus à rien. Ce que je voudrais faire ça serait bloquer la taille du jpanel et quand son conteneur (le jsplitpane, enfin on peut même dire la frame vu qu'il n'y a que lui à ce niveau) devient plus petit que lui en hauteur, ben j'ai une scrollbar verticale plutôt que ma mise en page qui part en vrille :/
    On pourrait résumer le code à ça (un poil simplifié pour éviter d'en mettre 12 pages) :
    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
    this.setJMenuBar(getJJMenuBar());
    this.setContentPane(getJContentPane());
    this.pack();
    this.setSize(600, 374);
    this.setExtendedState(this.getExtendedState()|MAXIMIZED_BOTH);
     
    this.setTitle("JFrame");
    this.addComponentListener(this);
    this.addKeyListener(this);
     
    private JPanel getJContentPane() {
    	if (jContentPane == null) {
    		BorderLayout borderLayout = new BorderLayout();
    		borderLayout.setHgap(0);
    		borderLayout.setVgap(0);
    		jContentPane = new JPanel();
    		jContentPane.setLayout(borderLayout);
    		jContentPane.add(getJSplitPane(), BorderLayout.CENTER);
    	}
    	return jContentPane;
    }
     
    private JSplitPane getJSplitPane() {
    	if (jSplitPane == null) {
    		labelOpengl = new JLabel();
    		//labelOpengl.setText("JLabel");
    		//labelOpengl.setMinimumSize(new Dimension(480,374));
    		labelOpengl.setMinimumSize(new Dimension(this.getWidth()-180,jContentPane.getHeight()));
    		jSplitPane = new JSplitPane();
    		jSplitPane.setRightComponent(labelOpengl);
    		jSplitPane.setDividerLocation(200);
    		jSplitPane.setContinuousLayout(true);
    		jSplitPane.setLeftComponent(getJPanel());
    		jSplitPane.setOneTouchExpandable(true);
    	}
    	return jSplitPane;
    }
     
    private JPanel getJPanel() {
    	if (jPanel == null) 
    	{
    		jPanel = new JPanel();
    		GridBagLayout gridbaglayout = new GridBagLayout();
    		jPanel.setAlignmentX(0);
    		jPanel.setAlignmentY(0);
    		jPanel.setLayout(gridbaglayout);
    		jPanel.setPreferredSize(new Dimension(180,jContentPane.getHeight()));
     
    		ajout des boutons et compagnie
    	}
    	return jPanel
    }
    J'ai regardé pas mal de trucs, et j'en ai testé pas mal aussi, JScrollPane dans lequel je mets mon JPanel, pas moyen de faire un scrolling vertical, alors que le horizontal passe tout seul ><, et j'ai aussi vaguement tenté de mettre directement une scrollbar au jPanel, mais bon, j'ai un peu de mal avec les scrollbar :/
    Donc si quelqu'un pouvait me dire comment je peux mettre un scrolling vertical sur mon jPanel pour que j'ai plus de problèmes de taille du contenu du jPanel, je lui en serait très reconnaissant^^

    Ah oui, et si vous voulez le code complet "ajout des boutons et compagnie" pour voir si y a pas un truc qui va pas, ben j'peux le rajouter (mais bon, c'est que des gridbagconstraints avec les options pour que toi soit bien placé à la bonne taile,...)

  2. #2
    Membre confirmé
    Inscrit en
    Septembre 2006
    Messages
    68
    Détails du profil
    Informations forums :
    Inscription : Septembre 2006
    Messages : 68
    Par défaut
    Je ne suis pas très expérimentée mais si j'ai bien compris, tes composants se reactualisent verticalement avec la largeur du panel? Estce que ca pourrait pas etre du au Layout interne ou à la définition du comportement de ce que tu mets dans les Grid?

  3. #3
    Membre averti
    Profil pro
    Inscrit en
    Mars 2007
    Messages
    21
    Détails du profil
    Informations personnelles :
    Âge : 41
    Localisation : France

    Informations forums :
    Inscription : Mars 2007
    Messages : 21
    Par défaut
    Non, en fait la largeur elle change jamais, c'est verticalement qu'ils se repositionnent, plus c'est petit verticalement et plus ils sont regroupés ensemble, à la fin j'ai un gros paté de composant au même endroit :/
    Dans le doute, voilà ce que je fais pour la mise en page :

    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
    private void add_ligne(JToggleButton jtogglebouton, JLabel jlabel, JButton jbouton, int row, int col)
    {
    	GridBagConstraints gridBagConstraints1 = new GridBagConstraints();
    	gridBagConstraints1.gridx = col;
    	gridBagConstraints1.gridy = row;
    	gridBagConstraints1.ipadx = -15;
    	gridBagConstraints1.ipady = 5;
    	//gridBagConstraints1.weightx = 1;
    	gridBagConstraints1.insets = new Insets(0,0,15,0);
    	//gridBagConstraints1.weighty = 1;
    	//gridBagConstraints1.fill = GridBagConstraints.PAGE_START;
    	GridBagConstraints gridBagConstraints2 = new GridBagConstraints();
    	gridBagConstraints2.gridx = col+1;
    	gridBagConstraints2.gridy = row;
    	gridBagConstraints2.gridwidth = 2;
    	//gridBagConstraints2.weightx = 1;
    	//gridBagConstraints1.weighty = 1;
    	gridBagConstraints2.insets = new Insets(0,0,15,0);
    	gridBagConstraints2.fill = GridBagConstraints.PAGE_START;
    	GridBagConstraints gridBagConstraints3 = new GridBagConstraints();
    	gridBagConstraints3.gridx = col+3;
    	gridBagConstraints3.gridy = row;
    	gridBagConstraints3.ipadx = -15;
    	gridBagConstraints3.ipady = -5;
    	//gridBagConstraints3.weightx = 1;
    	//gridBagConstraints1.weighty = 1;
    	gridBagConstraints3.insets = new Insets(0,0,15,0);
    	gridBagConstraints3.fill = GridBagConstraints.PAGE_START;
     
    	jPanel.add(jtogglebouton, gridBagConstraints1);
    	jPanel.add(jlabel, gridBagConstraints2);
    	jPanel.add(jbouton, gridBagConstraints3);
    }
     
    private void add_bouton(JButton jbouton, int row, int col)
    {
    	GridBagConstraints gridBagConstraints1 = new GridBagConstraints();
    	gridBagConstraints1.gridx = col;
    	gridBagConstraints1.gridy = row;
    	gridBagConstraints1.ipadx = 80;
    	gridBagConstraints1.ipady = 10;
    	gridBagConstraints1.weightx = 1;
    	gridBagConstraints1.insets = new Insets(0,0,15,0);
    	gridBagConstraints1.gridwidth = 4;
    	//gridBagConstraints1.weighty = 1;
    	//gridBagConstraints1.fill = GridBagConstraints.PAGE_START;
     
    	jPanel.add(jbouton, gridBagConstraints1);
    }
     
    private void add_boutons(Component bouton, int row, int col)
    {
    	GridBagConstraints gridBagConstraints1 = new GridBagConstraints();
    	gridBagConstraints1.gridx = col;
    	gridBagConstraints1.gridy = row;
    	gridBagConstraints1.ipadx = -25;
    	//gridBagConstraints1.ipady = 40;
    	gridBagConstraints1.weightx = 0.1;
    	gridBagConstraints1.insets = new Insets(0,0,0,0);
    	//gridBagConstraints1.gridwidth = 3;
    	//gridBagConstraints1.weighty = 1;
    	//gridBagConstraints1.fill = GridBagConstraints.PAGE_START;
     
    	jPanel.add(bouton, gridBagConstraints1);
    }
    Et dans getJPanel() j'appelle ça à l'endroit "ajout des boutons et compagnie":
    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
    add_ligne(getTogglePoint(), getLabelPoint(), getConfigPoints(),0,0);
    add_ligne(getToggleMaillage(), getLabelMaillage(), getConfigMaillage(),1,0);
    add_ligne(getToggleOmbrages(), getLabelOmbrages(), getConfigOmbrages(),2,0);
    add_ligne(getToggleChamp(), getLabelChamp(), getConfigChamp(),3,0);
    add_ligne(getToggleNormales(), getLabelNormales(), getConfigNormales(),4,0);
    add_ligne(getToggleLumiere(), getLabelLumiere(), getConfigLumiere(),5,0);
    add_ligne(getToggleTransparence(), getLabelTransparence(), getConfigTransparence(),6,0);
    add_bouton(getConfigObjets(),7,0);
    add_boutons(getToggleSelection(),8,0);
    add_boutons(getToggleTranslation(),8,1);
    add_boutons(getToggleZoom(),8,2);
    add_boutons(getToggleInfo3D(),8,3);
    add_boutons(getToggleRotx(),9,0);
    add_boutons(getToggleRoty(),9,1);
    add_boutons(getToggleRotz(),9,2);
    add_boutons(getToggleRotecran(),9,3);
    add_boutons(getInfoangle(),10,0);
    add_boutons(getInfotranslation(),10,1);
    add_boutons(getTexte(),10,2);
    add_boutons(getTriedre(),10,3);
    add_boutons(getToggleMarquefac(),11,0);
    add_boutons(getToggleFaceInfo(),11,1);
    add_boutons(getToggleMarquesom(),11,2);
    add_boutons(getToggleInfosom(),11,3);
    add_boutons(getSelecFacette(),12,0);
    add_boutons(getModifAttribut(),12,1);
    add_boutons(getToggleZbuffer(),12,2);
    add_boutons(getToggleCullface(),12,3);
    J'suis arrivé à avoir la mise en page qu'il me fallat en tatonnant, donc y a des chances que tout ça, ça soit tout pourri.

    edit : j'ai oublié de préciser, je suis obligé de développer avec du java 1.4.2

Discussions similaires

  1. Une image dans un Jpanel dans un Jpanel dans un Jframe
    Par ThomasH dans le forum Agents de placement/Fenêtres
    Réponses: 9
    Dernier message: 09/12/2009, 20h23
  2. Récupérer JPanel dans un JScrollPane dans un JTabbedPane
    Par orochimaru13 dans le forum AWT/Swing
    Réponses: 2
    Dernier message: 16/05/2008, 11h02
  3. problème affichage JPanel dans un JPanel
    Par rburney dans le forum AWT/Swing
    Réponses: 2
    Dernier message: 02/04/2008, 11h36
  4. Position Jpanel dans un Jpanel
    Par arnauld_2 dans le forum AWT/Swing
    Réponses: 1
    Dernier message: 28/12/2007, 17h52
  5. IHM - Inclure un JPanel dans un JPanel
    Par fouinny dans le forum AWT/Swing
    Réponses: 1
    Dernier message: 08/04/2007, 22h08

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