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

NetBeans Java Discussion :

Netbeans JComboBox java.lang.ClassCastException


Sujet :

NetBeans Java

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre éclairé
    Inscrit en
    Mai 2003
    Messages
    351
    Détails du profil
    Informations forums :
    Inscription : Mai 2003
    Messages : 351
    Par défaut Netbeans JComboBox java.lang.ClassCastException
    Bojour,
    je suis confronté à une erreur avec JTable, JComboBox.
    J'ai crées un JTable basée sur une table operation (MYSQL).
    Par défaut Netbeans n'utilise que des JTextField. Je veux mettre à la place d'un d'un JtextField un JComboxBox car certains éléments doivent être selectionnés et non saisis par l'utilisation (ces éléments proviennent des tables paramètres)
    alors 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
    comboBox = new javax.swing.JComboBox();
    comboBox.setName("comboBox"); // NOI18N
    org.jdesktop.swingbinding.JComboBoxBinding jComboBoxBinding1 = org.jdesktop.swingbinding.SwingBindings.createJComboBoxBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, structureList, comboBox);
    bindingGroup.addBinding(jComboBoxBinding1);
    // Code adding the component to the parent container - not shown here
    comboBox.setRenderer(new DefaultListCellRenderer() {
               @Override
               public Component getListCellRendererComponent(
                       JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
                   super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
                   if (value instanceof Structure) {
                       Structure s = (Structure)value;
                       setText(s.getCode());
                   }
                   return this;
               }
           });
     
    masterTable.getColumnModel().getColumn(0).setCellEditor(new DefaultCellEditor(comboBox));
    masterScrollPane.setViewportView(masterTable);
    A l'exécution j'ai l'erreur suivante quand je sélectionne un élément dans la JComboBox :
    run:
    [TopLink Info]: 2009.09.24 08:43:13.906--ServerSession(24622029)--TopLink, version: Oracle TopLink Essentials - 2.0.1 (Build b09d-fcs (12/06/2007))
    [TopLink Info]: 2009.09.24 08:43:14.312--ServerSession(24622029)--file:/C:/workspace/Netbeans/Gestcom/build/classes/-gestcomPU login successful
    Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException
    at java.lang.Class.cast(Class.java:2990)
    at org.jdesktop.beansbinding.Binding.convertReverse(Binding.java:1321)
    at org.jdesktop.beansbinding.Binding.getTargetValueForSource(Binding.java:909)
    at org.jdesktop.beansbinding.Binding.saveUnmanaged(Binding.java:1268)
    at org.jdesktop.swingbinding.JTableBinding$ColumnBinding.saveUnmanaged0(JTableBinding.java:654)
    at org.jdesktop.swingbinding.JTableBinding$ColumnBinding.access$1800(JTableBinding.java:542)
    at org.jdesktop.swingbinding.JTableBinding$BindingTableModel.setValueAt(JTableBinding.java:745)
    at javax.swing.JTable.setValueAt(JTable.java:2719)
    at javax.swing.JTable.editingStopped(JTable.java:4721)
    at javax.swing.AbstractCellEditor.fireEditingStopped(AbstractCellEditor.java:125)
    at javax.swing.DefaultCellEditor$EditorDelegate.stopCellEditing(DefaultCellEditor.java:350)
    at javax.swing.DefaultCellEditor$3.stopCellEditing(DefaultCellEditor.java:140)
    at javax.swing.DefaultCellEditor.stopCellEditing(DefaultCellEditor.java:215)
    at javax.swing.DefaultCellEditor$EditorDelegate.actionPerformed(DefaultCellEditor.java:367)
    at javax.swing.JComboBox.fireActionEvent(JComboBox.java:1240)
    at javax.swing.JComboBox.setSelectedItem(JComboBox.java:567)
    at javax.swing.JComboBox.setSelectedIndex(JComboBox.java:603)
    at javax.swing.plaf.basic.BasicComboPopup$Handler.mouseReleased(BasicComboPopup.java:816)
    at java.awt.AWTEventMulticaster.mouseReleased(AWTEventMulticaster.java:273)
    at java.awt.Component.processMouseEvent(Component.java:6263)
    at javax.swing.JComponent.processMouseEvent(JComponent.java:3267)
    at javax.swing.plaf.basic.BasicComboPopup$1.processMouseEvent(BasicComboPopup.java:480)
    at java.awt.Component.processEvent(Component.java:6028)
    at java.awt.Container.processEvent(Container.java:2041)
    at java.awt.Component.dispatchEventImpl(Component.java:4630)
    at java.awt.Container.dispatchEventImpl(Container.java:2099)
    at java.awt.Component.dispatchEvent(Component.java:4460)
    at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4574)
    at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4238)
    at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4168)
    at java.awt.Container.dispatchEventImpl(Container.java:2085)
    at java.awt.Window.dispatchEventImpl(Window.java:2475)
    at java.awt.Component.dispatchEvent(Component.java:4460)
    Merci pour votre aide

  2. #2
    Membre Expert
    Avatar de X-plode
    Ingénieur développement logiciels
    Inscrit en
    Décembre 2005
    Messages
    682
    Détails du profil
    Informations professionnelles :
    Activité : Ingénieur développement logiciels

    Informations forums :
    Inscription : Décembre 2005
    Messages : 682
    Par défaut
    Bonjour,

    Ton problème vient d'ici :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    Structure s = (Structure)value;
    En l'occurence, si tu fais ceci :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
     
     if (value instanceof Structure) {
                       Structure s = new Structure();
                       value = s;
                       s = (Structure)value;
                       setText(s.getCode());
     }
    Normalement, ça devrait marcher

  3. #3
    Membre éclairé
    Inscrit en
    Mai 2003
    Messages
    351
    Détails du profil
    Informations forums :
    Inscription : Mai 2003
    Messages : 351
    Par défaut
    j'ai essayé ton code mais cela ne marche pas. Quand j'exécute ton code il ne me renvoie pas les données paramètres de la table. la JCombobox est vide

Discussions similaires

  1. erreur java java.lang.ClassCastException
    Par yLaplace dans le forum Langage
    Réponses: 1
    Dernier message: 14/04/2007, 18h17
  2. pb java.lang.ClassCastException: $Proxy84
    Par chakala dans le forum Wildfly/JBoss
    Réponses: 10
    Dernier message: 15/03/2007, 14h21
  3. JSP javamail java.lang.ClassCastException
    Par itr dans le forum Servlets/JSP
    Réponses: 6
    Dernier message: 14/06/2006, 17h01
  4. [EJB3] java.lang.ClassCastException
    Par n00noors dans le forum Java EE
    Réponses: 9
    Dernier message: 21/02/2006, 15h06
  5. Réponses: 16
    Dernier message: 10/01/2006, 22h02

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