javax.swing.JTextField.getSelectedText()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(4.0k)|赞(0)|评价(0)|浏览(353)

本文整理了Java中javax.swing.JTextField.getSelectedText()方法的一些代码示例,展示了JTextField.getSelectedText()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JTextField.getSelectedText()方法的具体详情如下:
包路径:javax.swing.JTextField
类名称:JTextField
方法名:getSelectedText

JTextField.getSelectedText介绍

暂无

代码示例

代码示例来源:origin: org.netbeans.api/org-openide-awt

@Override
public void mouseClicked(MouseEvent e) {
  if( e.getClickCount() == 1 ) {
    if( null != txtLocation.getSelectedText()
        || txtLocation.isFocusOwner() )
      return;
    txtLocation.selectAll();
  }
}

代码示例来源:origin: tomighty/tomighty

@Override
public void keyTyped(KeyEvent e) {
  if(!Character.isDigit(e.getKeyChar())) {
    e.consume();
    return;
  }
  JTextField field = (JTextField) e.getSource();
  String text = field.getText();
  if(text == null) return;
  boolean reachedMaxLength = text.length() >= maxLength;
  boolean noTextSelected = field.getSelectedText() == null;
  if(reachedMaxLength && noTextSelected) {
    e.consume();
  }
}

代码示例来源:origin: ontop/ontop

private String getExistingText() {
  String existingText = textFieldOnFocus.getText();
  String selectedText = textFieldOnFocus.getSelectedText();
  if (selectedText != null) {
    return existingText.replace(selectedText, ""); // remove text on highlight
  } else {
    return existingText;
  }
}

代码示例来源:origin: org.databene/databene-commons

@Override
public void actionPerformed(ActionEvent e) {
  Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
  String textToCopy = textField.getSelectedText();
  if (textToCopy == null)
    textToCopy = textField.getText();
  StringSelection selection = new StringSelection(textToCopy);
  clipboard.setContents(selection, selection);
}

代码示例来源:origin: org.verapdf.apps/gui

@Override
public void keyTyped(KeyEvent e) {
  char c = e.getKeyChar();
  if ((field.getText().length() == 6)
      && ((field.getSelectedText() == null) || (field.getSelectedText().length() == 0))
      && (c != KeyEvent.VK_BACK_SPACE) && (c != KeyEvent.VK_DELETE)) {
    e.consume();
  } else if (c == '0'
      && ((!fromZero && field.getText().length() == 0) || field.getText().startsWith("0"))) {
    e.consume();
  } else if (!(((c >= '0') && (c <= '9')) || (c == KeyEvent.VK_BACK_SPACE)
      || (c == KeyEvent.VK_DELETE))) {
    e.consume();
  }
}

代码示例来源:origin: com.github.waikato/fcms-widgets

/**
 * Copies the current settings to the clipboard.
 */
protected void copyToClipboard() {
 if (m_TextSelection.getSelectedText() == null)
  ClipboardHelper.copyToClipboard(m_TextSelection.getText());
 else
  ClipboardHelper.copyToClipboard(m_TextSelection.getSelectedText());
}

代码示例来源:origin: blurpy/kouchat

@Override
public void popupMenuWillBecomeVisible(final PopupMenuEvent e) {
  if (textfield.getSelectedText() == null) {
    copyMI.setEnabled(false);
    cutMI.setEnabled(false);
  }
  else {
    copyMI.setEnabled(true);
    cutMI.setEnabled(true);
  }
  if (textfield.getText().length() > 0) {
    clearMI.setEnabled(true);
  } else {
    clearMI.setEnabled(false);
  }
}

代码示例来源:origin: com.github.waikato/fcms-widgets

if (isInlineEditingEnabled()) {
caret += clipboard.length();
if (m_TextSelection.getSelectedText() == null) {
 text = new StringBuilder(m_TextSelection.getText());
 text.insert(m_TextSelection.getCaretPosition(), clipboard);

代码示例来源:origin: tinyMediaManager/tinyMediaManager

if (editorComponent instanceof JTextField) {
 JTextField tf = (JTextField) editorComponent;
 String selectedText = tf.getSelectedText();
 if (selectedText != null) {
  tf.setSelectionStart(0);

代码示例来源:origin: tinyMediaManager/tinyMediaManager

if (editorComponent instanceof JTextField) {
 JTextField tf = (JTextField) editorComponent;
 String selectedText = tf.getSelectedText();
 if (selectedText != null) {
  tf.setSelectionStart(0);

代码示例来源:origin: tinyMediaManager/tinyMediaManager

if (editorComponent instanceof JTextField) {
 JTextField tf = (JTextField) editorComponent;
 String selectedText = tf.getSelectedText();
 if (selectedText != null) {
  tf.setSelectionStart(0);

代码示例来源:origin: tinyMediaManager/tinyMediaManager

if (editorComponent instanceof JTextField) {
 JTextField tf = (JTextField) editorComponent;
 String selectedText = tf.getSelectedText();
 if (selectedText != null) {
  tf.setSelectionStart(0);

代码示例来源:origin: tinyMediaManager/tinyMediaManager

if (editorComponent instanceof JTextField) {
 JTextField tf = (JTextField) editorComponent;
 String selectedText = tf.getSelectedText();
 if (selectedText != null) {
  tf.setSelectionStart(0);

相关文章

JTextField类方法