示例#1
0
  XTextFieldPeer(TextField target) {
    super(target);
    text = target.getText();
    xtext = new XAWTTextField(text, this, target.getParent());
    xtext.getDocument().addDocumentListener(xtext);
    xtext.setCursor(target.getCursor());
    XToolkit.specialPeerMap.put(xtext, this);

    initTextField();
    setText(target.getText());
    if (target.echoCharIsSet()) {
      setEchoChar(target.getEchoChar());
    } else setEchoChar((char) 0);

    int start = target.getSelectionStart();
    int end = target.getSelectionEnd();
    // Fix for 5100200
    // Restoring Motif behaviour
    // Since the end position of the selected text can be greater than the length of the text,
    // so we should set caret to max position of the text
    setCaretPosition(Math.min(end, text.length()));
    if (end > start) {
      // Should be called after setText() and setCaretPosition()
      select(start, end);
    }

    setEditable(target.isEditable());

    // After this line we should not change the component's text
    firstChangeSkipped = true;
    AWTAccessor.getComponentAccessor().setPeer(xtext, this);
  }
示例#2
0
  void initialize() {
    int start, end;

    TextField txt = (TextField) target;

    setText(txt.getText());
    if (txt.echoCharIsSet()) {
      setEchoChar(txt.getEchoChar());
    }

    start = txt.getSelectionStart();
    end = txt.getSelectionEnd();

    if (end > start) {
      select(start, end);
    } else {
      setCaretPosition(start);
    }

    if (!target.isBackgroundSet()) {
      // This is a way to set the background color of the TextArea
      // without calling setBackground - go through native C code
      setTargetBackground(SystemColor.text);
    }
    if (!target.isForegroundSet()) {
      target.setForeground(SystemColor.textText);
    }

    setEditable(txt.isEditable());

    //	oldSelectionStart = -1; // accessibility support
    //	oldSelectionEnd = -1;	// accessibility support

    super.initialize();
  }