10 Replies Latest reply: May 12, 2009 2:37 AM by 843851 RSS

    Hsinglelineentry is not working

    843851
      dear all,
      i am using Xletview 0.3.6 as an emulator and i wanted to have a text input so i used the component HSingleLineEntry the problem is that although it have the focus nothing is inserted when i click on the remote control can some help me and tell me how to insert text not only numbers
      my code:
      HSinglelineEntry textInput = new HSinglelineEntry(10, 10, 400, 300);
                textInput.setBackground(Color.red);
                textInput.setFont(new Font("Tiresias",Font.PLAIN,20));
                 textInput.setForeground(Color.blue);
                textInput.setCaretCharPosition(0);
                
                try {
                     textInput.setLook(new HSinglelineEntryLook());
                } catch (HInvalidLookException e) {
                     // TODO Auto-generated catch block
                     e.printStackTrace();
                }
                     textInput.setVisible(true);
                
                //textInput.setTextContent("some text", textInput.ALL_STATES);
                HTextEvent startEvent = new HTextEvent(textInput,HTextEvent.TEXT_START_CHANGE);
                textInput.processHTextEvent(startEvent);
                textInput.addHKeyListener(this);
                scene.add(textInput);
                textInput.requestFocus();
      another question i didn't find any open sources Java TV or MHP applications even basic ones can someone guide where i can find some
      Thanks
        • 1. Re: Hsinglelineentry is not working
          843851
          Hi, have you set      setEditMode like this:
          textInput.setEditMode(true)
          ??
          • 2. Re: Hsinglelineentry is not working
            843851
            Setting editMode doesn't helps.
            • 3. Re: Hsinglelineentry is not working
              843851
              As far as I know, you have to push enter button when the text entry component is focused, to edit it, but to avoid this if you could set the edit mode to true when the input component is in focused state (addFocuslListener and OnFocusGain--> textEditMode=true). Althougt doing this I found another problem, which is that when you are writing some text in an input the arrow buttons doesn't function (the correspondent event is not thrown), to move from one to another component, untill you presh EXIT.

              I hope it will help you.

              Greetings
              • 4. Re: Hsinglelineentry is not working
                843851
                hi apenz,

                Would u please share some code example ? when i use Hsinglelineentry in xlet viewer, same problem.. :( can get focus, but cannot edit:(
                • 5. Re: Hsinglelineentry is not working
                  843851
                  When you have the focus in a HSingleEntry you have to push OK button of your remote control to write inside it.
                  I paste here some code that could be helpful:

                  I define some variables related to the textbox (HSingleEntry) in the class that extends HComponent where will be added:
                       private HSinglelineEntry nameTextBox;
                       
                       private  float nameTextBoxFx=0.2f;
                       private  float nameTextBoxFy=0.20f;
                       
                       private  float nameTextBoxWidth=0.2f;
                       private  float nameTextBoxHeight=0.07f;
                       
                       private final DVBColor nameTextBoxBackColor=new DVBColor(255,255,255,255);//100
                       private final DVBColor nameTextBoxForeColor=new DVBColor(0,0,0,255);//150
                  then I create the component and I add it to the window
                            nameTextBox=new HSinglelineEntry();
                            nameTextBox.setLocation(Math.round(nameTextBoxFx*width),Math.round(nameTextBoxFy*height));
                            nameTextBox.setSize(Math.round(nameTextBoxWidth*width),Math.round(nameTextBoxHeight*height));
                            nameTextBox.setName("nameTextBox");
                            nameTextBox.setType(HKeyboardInputPreferred.INPUT_ALPHA);
                            
                            //Style
                            nameTextBox.setBackgroundMode(HVisible.BACKGROUND_FILL);
                            nameTextBox.setBackground(nameTextBoxBackColor);
                            nameTextBox.setForeground(nameTextBoxForeColor);
                            nameTextBox.setHorizontalAlignment(HSinglelineEntry.HALIGN_LEFT);
                  
                                 this.add(nameTextBox);
                  cheers
                  • 6. Re: Hsinglelineentry is not working
                    843851
                    HI apenz,

                    thanks for the reply:)

                    Got another question need ur expertise.... when I am using alticast's STB, i notice for HGraphicButton, pressing VK_ENTER when it is in Focused state, it seems no event will be fired to KeyListener registered on that HGraphicButton ? but when pressing other keys, the keyEvent can be received... any idea?

                    My first draft of code,

                    cancelButton.addKeyListener(
                    new KeyListener(){
                    public void keyPressed (KeyEvent key){
                    -----output debug message here
                    }
                    });

                    after i did not get keyEvent when pressing Enter, I change the inner class to ,

                    Class A implements KeyListener{

                    cancelButton.addKeyListener(this);
                    public void keyPressed (KeyEvent key){
                    -----output debug message here
                    }

                    }

                    when pressing ENTER, still no debug message printed out... but if I click keys like "1", "2".... the debug msg will be printed out...

                    So does it mean that VK_ENTER will not be fired? thanks:)
                    • 7. Re: Hsinglelineentry is not working
                      843851
                      The event to listen when you press a button is a HActionEvent, so you have to implement a HActionListener class.
                      you're welcome

                      Edited by: apenz on May 7, 2009 9:57 AM
                      • 8. Re: Hsinglelineentry is not working
                        843851
                        thanks apenz
                        • 9. Re: Hsinglelineentry is not working
                          843851
                          Hi apenz,

                          Currently I want to have a scrolling HGraphicButton list... but seems my HGraphicButton does not respond to any key event, but only respond to action event, (even I add a keyListener to the HGraphicButton, no key event fired when pressing keys like left and right).... so when a HGraphicButton is with focus, I cannot distinguish from left key pressed and right key pressed? any idea? thanks.
                          • 10. Re: Hsinglelineentry is not working
                            843851
                            Hi nedved.yang,

                            In your focusListener function you just have to check the name of the component which generated this event:
                            HComponent focusedComponent=(HComponent)evt.getComponent();
                            if(focusedComponent.getName().equals(your_component_name))
                            And to catch general user key inputs you have to create a
                                 
                                        static{
                                      arrowAndNumberKeyEvents=new UserEventRepository("Arrow ");
                                      arrowAndNumberKeyEvents.addAllArrowKeys();
                            
                                 }
                            and then add the HComponent element itself as listener
                                      EventManager.getInstance().addUserEventListener(this, arrowAndNumberKeyEvents);
                            Implementing UserEventListener functions
                                 public void userEventReceived(UserEvent evt) {
                                      HKeyEvent action=new HKeyEvent(this, evt.getType(),evt.getWhen(),evt.getModifiers(),evt.getCode(),evt.getKeyChar());
                                      switch(evt.getType()){
                                      case HKeyEvent.KEY_PRESSED:
                                           Logger.debug(this,"Pressed key= "+action.getKeyChar());
                                           for(int i=0;i<keyListeners.size();i++){
                                                ((HKeyListener)keyListeners.elementAt(i)).keyPressed(action);
                                           }
                                           break;
                                      case HKeyEvent.KEY_RELEASED:
                                           for(int i=0;i<keyListeners.size();i++){
                                                ((HKeyListener)keyListeners.elementAt(i)).keyReleased(action);
                                           }
                                           break;
                                      case HKeyEvent.KEY_TYPED:
                                           for(int i=0;i<keyListeners.size();i++){
                                                ((HKeyListener)keyListeners.elementAt(i)).keyTyped(action);
                                           }
                                           break;
                                      }
                                      
                                 }
                            Then in the HKeyListener function keyPressed implement what to do for each pressed button

                            greetings