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 :

Mon JScrollPane ne veut pas de mon JPanel


Sujet :

AWT/Swing Java

  1. #1
    Membre éprouvé Avatar de Lady
    Femme Profil pro
    Développeur Java
    Inscrit en
    Mars 2003
    Messages
    678
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : France, Nord (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Développeur Java
    Secteur : Santé

    Informations forums :
    Inscription : Mars 2003
    Messages : 678
    Points : 909
    Points
    909
    Par défaut Mon JScrollPane ne veut pas de mon JPanel
    bonjour j'ai un petit problème d'illégalArgumentException :

    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
     
    import javax.swing.JCheckBox;
    import javax.swing.JPanel;
    import javax.swing.JScrollPane;
     
     
    public class AlphaListenerScrollPanel extends JScrollPane{
     
    	JCheckBox[] _list;
     
     
    	AlphaListenerScrollPanel(String[] list)
    	{
    		super();
     
    		_list = new JCheckBox[list.length];
    		for (int i = 0; i< list.length; i++)
    		{
    			JCheckBox jc = new JCheckBox(list[i],true);
    			_list[i] = jc;
    		}
    		this.add(new AlphaPanel(_list));
    	}
     
    	private class AlphaPanel extends JPanel
    	{
    		AlphaPanel(JCheckBox[] list)
    		{
    			super();
    			this.setLayout(null);
    			int pos = 0;
    			for (int i =0 ; i< list.length ; i++)
    			{
    				list[i].setBounds(0,pos , this.getWidth(), 20);
    				this.add(list[i]);
    				pos = pos + 20;
    			}
    		}
    	}
     
    	public String[] getSelectedString()
    	{
    		int count = 0;
    		for (int i = 0 ; i< _list.length; i++)
    		{
    			if (_list[i].isSelected()) count++;
    		}
    		String[] selection = new String[count];
    		count = 0;
    		for (int i = 0 ; i< _list.length; i++)
    		{
    			if (_list[i].isSelected())
    				{
    					selection[count] = _list[i].getText();
    					count++;
    				}
    		}
    		return selection;
    	}
    }
    et ma petit erreur :

    Exception during event dispatch:
    java.lang.IllegalArgumentException
    at javax.swing.ScrollPaneLayout.addLayoutComponent(libgcj.so.7rh)
    at java.awt.Container.addImpl(libgcj.so.7rh)
    at java.awt.Container.add(libgcj.so.7rh)
    at AlphaListenerScrollPanel.<init>(AlphaListenerScrollPanel.java:21)
    at SelectionPanel.<init>(SelectionPanel.java:16)
    at MainFrame$PushListener.actionPerformed(MainFrame.java:43)
    at javax.swing.AbstractButton.fireActionPerformed(libgcj.so.7rh)
    at javax.swing.AbstractButton$1.actionPerformed(libgcj.so.7rh)
    at javax.swing.DefaultButtonModel.fireActionPerformed(libgcj.so.7rh)
    at javax.swing.DefaultButtonModel.setPressed(libgcj.so.7rh)
    at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(libgcj.so.7rh)
    at java.awt.Component.processMouseEvent(libgcj.so.7rh)
    at java.awt.Component.processEvent(libgcj.so.7rh)
    at java.awt.Container.processEvent(libgcj.so.7rh)
    at java.awt.Component.dispatchEventImpl(libgcj.so.7rh)
    at java.awt.Container.dispatchEventImpl(libgcj.so.7rh)
    at java.awt.Component.dispatchEvent(libgcj.so.7rh)
    at java.awt.LightweightDispatcher.handleMouseEvent(libgcj.so.7rh)
    at java.awt.LightweightDispatcher.dispatchEvent(libgcj.so.7rh)
    at java.awt.Container.dispatchEventImpl(libgcj.so.7rh)
    at java.awt.Window.dispatchEventImpl(libgcj.so.7rh)
    at java.awt.Component.dispatchEvent(libgcj.so.7rh)
    at java.awt.EventQueue.dispatchEvent(libgcj.so.7rh)
    at java.awt.EventDispatchThread.run(libgcj.so.7rh)

    ligne 21 ===> this.add(new AlphaPanel(_list));

    une idée (un truc que j'ai surement mal fait ...)

  2. #2
    Expert éminent sénior
    Avatar de adiGuba
    Homme Profil pro
    Développeur Java/Web
    Inscrit en
    Avril 2002
    Messages
    13 938
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Développeur Java/Web
    Secteur : Transports

    Informations forums :
    Inscription : Avril 2002
    Messages : 13 938
    Points : 23 190
    Points
    23 190
    Billets dans le blog
    1
    Par défaut
    Salut,


    Il ne faut pas ajouter de composants dans un JScrollPane, mais le définir en tant que "vue". Remplaces ton add() par ceci :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    this.setViewportView(new AlphaPanel(_list));
    Plus d'info : setViewportView()

    a++

  3. #3
    Membre éprouvé Avatar de Lady
    Femme Profil pro
    Développeur Java
    Inscrit en
    Mars 2003
    Messages
    678
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : France, Nord (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Développeur Java
    Secteur : Santé

    Informations forums :
    Inscription : Mars 2003
    Messages : 678
    Points : 909
    Points
    909
    Par défaut
    Citation Envoyé par adiGuba
    Salut,


    Il ne faut pas ajouter de composants dans un JScrollPane, mais le définir en tant que "vue". Remplaces ton add() par ceci :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    this.setViewportView(new AlphaPanel(_list));
    Plus d'info : setViewportView()

    a++
    oki merci .. fo dire que je n'ai jamais rien mis dans un JScrollPane si ce n'est dans le constructeur .. mais la je pouvais pas ...
    *Je vais donc m'endormir moin idiote ce soir ^^ !!*

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

Discussions similaires

  1. Pourquoi PHPMYADmin 2.9.0.3 veut pas de mon SQL ?
    Par santiago_cw dans le forum Débuter
    Réponses: 8
    Dernier message: 30/12/2006, 21h04
  2. Mon JScrollPane ne scroll pas
    Par sorry60 dans le forum AWT/Swing
    Réponses: 1
    Dernier message: 11/12/2006, 09h53
  3. tomcat ne veut pas démarrer mon projet
    Par diamonds dans le forum Tomcat et TomEE
    Réponses: 2
    Dernier message: 10/12/2006, 01h48
  4. mon "insert" ne veut pas marcher !!
    Par harlock59 dans le forum SQL Procédural
    Réponses: 3
    Dernier message: 02/01/2006, 13h17
  5. Mon ordinateur ne veut pas demarrer.
    Par JavaAcro dans le forum Ordinateurs
    Réponses: 11
    Dernier message: 17/12/2005, 11h40

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