コード例 #1
0
ファイル: XTextFieldPeer.java プロジェクト: FauxFaux/jdk9-jdk
  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
ファイル: XTextFieldPeer.java プロジェクト: FauxFaux/jdk9-jdk
 private void setXAWTTextField(String txt) {
   text = txt;
   if (xtext != null) {
     // JTextField.setText() posts two different events (remove & insert).
     // Since we make no differences between text events,
     // the document listener has to be disabled while
     // JTextField.setText() is called.
     xtext.getDocument().removeDocumentListener(xtext);
     xtext.setText(txt);
     if (firstChangeSkipped) {
       postEvent(new TextEvent(target, TextEvent.TEXT_VALUE_CHANGED));
     }
     xtext.getDocument().addDocumentListener(xtext);
     xtext.setCaretPosition(0);
   }
 }