1 Reply Latest reply: Jul 29, 2008 11:13 AM by 843851 RSS

    HText and HSinglelineEntry

    843851
      Hey guys, I was trying two approaches to the input system in a xlet, but in each one I got problems.

      So they are:

      - I wanted a simple numeric entry, so I thought it would be cool make a label, that changes its value when a key is pressed.
      The problem is that HText cannot change the content!
      I thought with another class, but the awt Label, for isntance, cannot receive focus.
      So, what class in Java world can change its content and receive focus?

      - The other aproach was the HSinglelineEntry.
      It receives focus, but I don't know how to make it be editable.
      Here is the code:
           public static HSinglelineEntry criarTextInput(int left, int top, int width, int height, int max) {
                System.out.println("Creating input text");
                HSinglelineEntry textInput = new HSinglelineEntry(left, top, width, height, max);
                textInput.setBackground(Color.red);
                textInput.setFont(new Font("Tiresias",Font.BOLD,20));
                 textInput.setForeground(Color.red);
                textInput.setCaretCharPosition(0);
                //textInput.addInputMethodListener(l)
                textInput.setType(HKeyboardInputPreferred.INPUT_NUMERIC);
      
                try {
                     textInput.setLook(new HSinglelineEntryLook());
                } catch (HInvalidLookException e) {
                     // TODO Auto-generated catch block
                     e.printStackTrace();
                }
      
                textInput.addKeyListener(xletApp); //xletApp is the xlet class itself
                //textInput.addHFocusListener(xletApp);
                
                scene.add(textInput);
                textInput.setTextContent("teste...", HState.ALL_STATES);
                HTextEvent startEvent = new HTextEvent(textInput,HTextEvent.TEXT_START_CHANGE);
                textInput.processHTextEvent(startEvent);
      
                textInput.setVisible(true);
                      textInput.setEditMode(true);
                
                return textInput;
           }
      Any idea is wellcome

      Leonardo