Zdravim,
http://coding.derkeiler.com/Archive/Java/comp.lang.java.gui/2005-12/msg00324.html pisu tam:

((JTextField)myJComboBox.getEditor().getEditorComponent()).setInputVerifier(comboVerifier);

a odpoved:

Ok, this works but I cannot access the methods of the JComboBox when
downcasting to a JTextField.

I wanted to verify that the entered value existed on the combo list.


If the edited value isn't in the list the SelectedIndex will be -1. If it is the SelectedIndex will be the index of the value.




ya

Arne  wrote / napísal(a):
 
Vazeni!
 Mam dotaz pro lidi, kteri delaji ve swingu.
 
 Potrebuji ve formulari v checkboxu, ktery je nastaven setEditable(true) pri
 opusteni pole zkontrolovat, jesli kod, ktery nekdo zada existuje v seznamu a
 pokud ne, tak ho zablokovat na tom policku, dokud ho neda spravne.
 
 Mam verifikator
 
     class ZkratkaExistsInputVerifier extends InputVerifier
     {
         public boolean verify(JComponent input)
         {   boolean ret= false;
             try {
                 String str = "";
                 str = (String) ((JComboBox) input).getSelectedItem();
 System.out.println("ZkratkaExistsInputVerifier:verify() str=" + str );          
      
                 
                 ret = klientiDB.isZkratka(str);
 System.out.println("ZkratkaExistsInputVerifier:verify() ret=" + ret );          
      
                 if (!ret)
                     createNewKlient(str);
                 
                 return ret;
             } catch (DBLibException ex) {
                 JOptionPane.showInternalMessageDialog(JobMDIApp.desktopPane,
                     ex.getLocalizedMessage(),
                     "Chyba["+getClass().getSimpleName()+"(1)]",
                     JOptionPane.ERROR_MESSAGE);
             }
             return ret;
         }
     }
 
 
 Nastavil jsem verifikator checkboxu
 
 comboZkrZakaznik.setInputVerifier(new ZkratkaExistsInputVerifier());
 
 Jenze pri opusteni ComboBoxu se metoda ZkratkaExistsInputVerifier.verify
 nespusti :( .
Predpokladal jsem, ze se bude verifikator chovat podobne, jako pri upusteni normalniho JTextField. Ale není tomu tak :(. 

 Je nejaka chyba v tomto postupu? 
 
 Nakonec jsem to vyresil v tridou v actionPerformed - jenze je to najiste a
 komplikovane. 
 Idealni by bylo zablokovani verifikatorem. Da se to nejak vyresit?
 
 (pracuji pod windows, programuji v NetBeans)
 
 
 Dekuji za odpovedi !
 
 Arne


  

Odpovedet emailem