4 Replies Latest reply: Feb 1, 2010 7:07 PM by 843851 RSS

    Hibrid Textbox some position numeric other characters

    843851
      Hi,

      In my application one entry textbox is for entering the identification string, that in Spain is composed by 8 numbers and one letter. I tried to change the imput mode based on the position of the cursor (enter text event), but it doesn't work, ¿can anyone help me?

      thanks in advance,
      greetings
        • 1. Re: Hibrid Textbox some position numeric other characters
          843851
          I think you must use HSinglelineEntry, add a KeyListener, and when a key is pressed you can count the number of characters (HSinglelineEntry.getTextContent(1).length);

          Creo que deberías usar HSinglelineEntry, puedes añadir un keyListener y cada vez que presione un tecla cuentas el número de caracteres totales (HSinglelineEntry.getTextContent(1).length);

          Saludos
          • 2. Re: Hibrid Textbox some position numeric other characters
            843851
            ¿Alguna idea de porque no funciona (ni siquiera entra en la función Listener)?/Any idea of why it doesn't work?(event doesn't enter in the listener function):
                 DNITextBox.setName("DNITextBox");
                      DNITextBox.addHKeyListener(new HKeyListener(){
            
                           public void keyPressed(KeyEvent kevt) {
                                // TODO Auto-generated method stub
                                Logger.debug(this, "**11**");
                                switch(kevt.getKeyCode()){
                                
                                     case HKeyEvent.VK_0:
                                     case HKeyEvent.VK_1:
                                     case HKeyEvent.VK_2:
                                     case HKeyEvent.VK_3:
                                     case HKeyEvent.VK_4:
                                     case HKeyEvent.VK_5:
                                     case HKeyEvent.VK_6:
                                     case HKeyEvent.VK_7:
                                     case HKeyEvent.VK_8:
                                     case HKeyEvent.VK_9:
                                          Logger.debug(this, "keypressed 0-9");
                                          HComponent component=(HComponent)controller.getScene().getFocusOwner();
                                          if(component.getName().equals("DNITextBox")){
                                               HSinglelineEntry dnibox=(HSinglelineEntry)component;
                                                    //Para cambiar el modo de escritura cuando llegue a la posicion de la letra o cuando vuelva a posiciones de número
                                               Logger.debug(this,"getCareCharPosition="+dnibox.getCaretCharPosition());
                                               if(dnibox.getCaretCharPosition()==7){
                                                    dnibox.setType(HKeyboardInputPreferred.INPUT_ALPHA);
                                               }
                                               else if(dnibox.getCaretCharPosition()==6){
                                                    dnibox.setType(HKeyboardInputPreferred.INPUT_NUMERIC);
                                               }
                                          }
                                          //repaint();
                                          break;
                                }     
                           
            • 3. Re: Hibrid Textbox some position numeric other characters
              843851
              Lo he conseguido/I managed to do it
                        DNITextBox.addHTextListener(new HTextListener(){
              
                             public void caretMoved(HTextEvent arg0) {
                                  int pos=DNITextBox.getCaretCharPosition();
                                  int type=DNITextBox.getType();
                                  if(pos==8){
                                       if(type==HSinglelineEntry.INPUT_NUMERIC){
                                            DNITextBox.setType(HSinglelineEntry.INPUT_ALPHA);
                                       }
                                  }else{
                                       if(type!=HSinglelineEntry.INPUT_NUMERIC){
                                            DNITextBox.setType(HSinglelineEntry.INPUT_NUMERIC);
                                       }
                                  }
                                  
                             }
              
                             public void textChanged(HTextEvent arg0) {
                                  // TODO Auto-generated method stub
                                  
                             }
                             
                        });
              Gracias por tu ayuda.
              • 4. Re: Hibrid Textbox some position numeric other characters
                843851
                hola Apenz

                Un favor sabes como capturar numeros de 2 y 3 caracteres usando keyPressed(KeyEvent e)

                ?

                Saludos

                Edited by: ulimed on Feb 1, 2010 5:05 PM