Forum |  HardWare.fr | News | Articles | PC | S'identifier | S'inscrire | Shop Recherche
1515 connectés 

  FORUM HardWare.fr
  Programmation
  Java

  Probleme pour placer des éléments swing

 


 Mot :   Pseudo :  
 
Bas de page
Auteur Sujet :

Probleme pour placer des éléments swing

n°1926723
Yop69
Posté le 25-09-2009 à 14:57:09  profilanswer
 

Bonjour,
 
Voila, j'ai un petit soucis pour placer des composants swing dans mon JPanel.  
http://photoyop.free.fr/a/d.png
Voici mon code

Code :
  1. public class HelloWorld extends JFrame {
  2.  
  3.     private static final long serialVersionUID = 1L;
  4.         
  5.     public static void main(String[] args) {
  6.         SwingUtilities.invokeLater(new Runnable() {
  7.             public void run() {
  8.                 HelloWorld f = new HelloWorld();
  9.                 f.setVisible(true);
  10.             }
  11.         });
  12.     }
  13.     
  14.     public HelloWorld() {
  15.         this.panel = new JPanel();
  16.         
  17.         this.tabp = new JTabbedPane();
  18.         ImageIcon icon = new ImageIcon("conf/star.png" );
  19.  
  20.         JPanel panel1 = makeTextPanel("Panel #1" );
  21.         this.tabp.addTab("Tab 1", icon, panel1, "Does nothing" );
  22.         JPanel panel2 = makeTextPanel("Panel #2" );
  23.         this.tabp.addTab("Tab 2", icon, panel2, "Does nothing" );
  24.         JPanel panel3 = makeTextPanel("Panel #3" );
  25.         this.tabp.addTab("Tab 3", icon, panel3, "Does nothing" );
  26.  
  27.         this.panel.add(this.tabp);
  28.         
  29.         getContentPane().add(this.panel, BorderLayout.CENTER);
  30.         getRootPane().requestFocus();
  31.         setMinimumSize( new Dimension( 640, 480) );
  32.         
  33.         this.radioButton(this.panel);
  34.         
  35.         this.txt = new JTextField(15);
  36.         this.panel.add(this.txt);
  37.         
  38.         JButton go = new JButton("Go" );
  39.         this.panel.add( new JButton("Go" ));
  40.         
  41.         this.scp = new JScrollPane();
  42.         this.scp.setBounds(100,100, 50 , 70);
  43.         this.scp.setVisible(true);
  44.         this.panel.add(this.scp);
  45.         
  46.         go.setToolTipText("Lancez la requête" );
  47.     }
  48.  
  49. protected JPanel makeTextPanel(String text) {
  50.        JPanel panel = new JPanel(false);
  51.        JLabel filler = new JLabel(text);
  52.        filler.setHorizontalAlignment(JLabel.CENTER);
  53.        //panel.setLayout(new GridLayout(0, 1));
  54.        panel.setLayout(new BorderLayout());
  55.        panel.add(filler);
  56.        return panel;
  57.    }
  58. }


 
J'aimerais avoir les 3 onglets à l'horizontal, au dessus des 5 boutons radio, du champ texte et d'envoi.
Et j'aimerais avoir un textarea en dessous de tout cela qui couvre toute la partie.
 
Je suis vraiment bloqué grrrr, j'aimerais bien avoir un IDE qui place les boutons et génère le code ! (ya un plugin pour cela sous eclipse ?)
(bon de toute façon, je m'en passe pour le moment pour bien apprendre à la mano ce que je fais)


Message édité par Yop69 le 25-09-2009 à 16:52:38
mood
Publicité
Posté le 25-09-2009 à 14:57:09  profilanswer
 

n°1926747
pataluc
Posté le 25-09-2009 à 16:08:24  profilanswer
 

la ligne 27 ne sert à rien, tu ajoute ton tabbedpane directement au contentpane de ta frame, et pas dans un panel qui est lui meme dans le contentpane...
 

Code :
  1. public class HelloWorld extends JFrame {
  2.    
  3.        private static final long serialVersionUID = 1L;
  4.            
  5.        public static void main(String[] args) {
  6.            SwingUtilities.invokeLater(new Runnable() {
  7.                public void run() {
  8.                    HelloWorld f = new HelloWorld();
  9.                    f.setVisible(true);
  10.                }
  11.            });
  12.        }
  13.        
  14.        public HelloWorld() {
  15.            
  16.            this.tabp = new JTabbedPane();
  17.            ImageIcon icon = new ImageIcon("conf/star.png" );
  18.    
  19.            JPanel panel1 = makeTextPanel("Panel #1" );
  20.            this.tabp.addTab("Tab 1", icon, panel1, "Does nothing" );
  21.            JPanel panel2 = makeTextPanel("Panel #2" );
  22.            this.tabp.addTab("Tab 2", icon, panel2, "Does nothing" );
  23.            JPanel panel3 = makeTextPanel("Panel #3" );
  24.            this.tabp.addTab("Tab 3", icon, panel3, "Does nothing" );
  25.                
  26.            getContentPane().add(this.tabp, BorderLayout.CENTER);
  27.            getRootPane().requestFocus();
  28.            setMinimumSize( new Dimension( 640, 480) );
  29.            
  30.            this.radioButton(this.panel);
  31.            
  32.            this.txt = new JTextField(15);
  33.            this.panel.add(this.txt);
  34.            
  35.            JButton go = new JButton("Go" );
  36.            this.panel.add( new JButton("Go" ));
  37.            
  38.            this.scp = new JScrollPane();
  39.            this.scp.setBounds(100,100, 50 , 70);
  40.            this.scp.setVisible(true);
  41.            this.panel.add(this.scp);
  42.            
  43.            go.setToolTipText("Lancez la requête" );
  44.        }
  45.    
  46.    protected JPanel makeTextPanel(String text) {
  47.           JPanel panel = new JPanel(false);
  48.           JLabel filler = new JLabel(text);
  49.           filler.setHorizontalAlignment(JLabel.CENTER);
  50.           //panel.setLayout(new GridLayout(0, 1));
  51.           panel.setLayout(new BorderLayout());
  52.           panel.add(filler);
  53.           return panel;
  54.       }
  55.    }

n°1926752
Yop69
Posté le 25-09-2009 à 16:47:35  profilanswer
 

[:alandon]  [:alandon]  [:alandon]  
Super merci pour ton aide !!
 
J'ai fait ceci comme conseillé :

Code :
  1. //this.panel.add(this.tabp);
  2. panel1.add(this.panel, BorderLayout.CENTER);
  3. getContentPane().add(this.tabp, BorderLayout.CENTER);

Message cité 1 fois
Message édité par Yop69 le 25-09-2009 à 16:47:45
n°1926754
Yop69
Posté le 25-09-2009 à 16:53:13  profilanswer
 

Zut il me reste le problème du JTextArea a placé en dessous des boutons radios  [:transparency]  :sweat:

n°1926756
pataluc
Posté le 25-09-2009 à 16:55:38  profilanswer
 

Yop69 a écrit :

[:alandon]  [:alandon]  [:alandon]  
Super merci pour ton aide !!
 
J'ai fait ceci comme conseillé :

Code :
  1. //this.panel.add(this.tabp);
  2. panel1.add(this.panel, BorderLayout.CENTER);
  3. getContentPane().add(this.tabp, BorderLayout.CENTER);



oui mais va au bout des choses, supprime complètement panel.

n°1926759
Yop69
Posté le 25-09-2009 à 16:59:44  profilanswer
 

bah non, dans mon panel, ya les boutons radios faut que je les garde :)
et après je dois régler mon problème du JTextArea a placer en dessous dans le layout de ce panel

n°1926762
pataluc
Posté le 25-09-2009 à 17:02:39  profilanswer
 

ah ok sorry je croyais que tu voulais mettre tes boutons radios dans un des onglets...

n°1926767
Yop69
Posté le 25-09-2009 à 17:15:52  profilanswer
 

Bah c'est ce que je veux et c'est ce qui se passe :)
 
http://photoyop.free.fr/a/e.png


Aller à :
Ajouter une réponse
  FORUM HardWare.fr
  Programmation
  Java

  Probleme pour placer des éléments swing

 

Sujets relatifs
Problème video sous IE[JS] Problème: ""null":Cannot convert undefined or null to object"
Problème accès fichier ....Problème avec onSoundComplete
Problème WPF / Entity Framework / Data BindingProblème image en FPDF
problème pour écrire un programmeproblème newsletter
[Resolu]Problème formulaireProblème de classe
Plus de sujets relatifs à : Probleme pour placer des éléments swing


Copyright © 1997-2022 Hardware.fr SARL (Signaler un contenu illicite / Données personnelles) / Groupe LDLC / Shop HFR