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

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

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

JTextArea.getSelectedText介绍

暂无

代码示例

代码示例来源:origin: net.sf.meka/meka

/**
 * Returns the underlying text.
 *
 * @return        the underlying text
 */
public String getSelectedText() {
  return m_TextCode.getSelectedText();
}

代码示例来源:origin: Waikato/meka

/**
 * Returns the underlying text.
 *
 * @return        the underlying text
 */
public String getSelectedText() {
  return m_TextCode.getSelectedText();
}

代码示例来源:origin: stackoverflow.com

final JTextArea textArea = new JTextArea();
 textArea.addCaretListener(new CaretListener() {
   @Override
   public void caretUpdate(CaretEvent e) {
     String selectedText = textArea.getSelectedText();
     // do something with it...
   }
 });

代码示例来源:origin: net.sf.squirrel-sql/squirrel-sql

private void onCopySelection()
{
 if(null == _txtArea.getSelectedText())
 {
   return;
 }
 Clipboard clip = Toolkit.getDefaultToolkit().getSystemClipboard();
 StringSelection data = new StringSelection(_txtArea.getSelectedText().trim());
 clip.setContents(data, data);
}

代码示例来源:origin: realXuJiang/bigtable-sql

private void onCopySelection()
{
 if(null == _txtArea.getSelectedText())
 {
   return;
 }
 Clipboard clip = Toolkit.getDefaultToolkit().getSystemClipboard();
 StringSelection data = new StringSelection(_txtArea.getSelectedText().trim());
 clip.setContents(data, data);
}

代码示例来源:origin: raydac/netbeans-mmd-plugin

private void buttonCopyActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonCopyActionPerformed
 StringSelection stringSelection = new StringSelection(this.editorPane.getSelectedText());
 final Clipboard clpbrd = Toolkit.getDefaultToolkit().getSystemClipboard();
 clpbrd.setContents(stringSelection, null);
}//GEN-LAST:event_buttonCopyActionPerformed

代码示例来源:origin: JGillam/burp-co2

@Override
  public void mouseReleased(MouseEvent e) {
    if (txtConsole.getSelectedText().length() > 0) {       // todo: this may generate a NullPointerException
      Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
      StringSelection contents = new StringSelection(txtConsole.getSelectedText());
      clipboard.setContents(contents, LaudanumClient.this);
    }
    txtConsole.setCaretPosition(txtConsole.getText().length());
  }
});

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-cnd-debugger-common2

private void maybeShowPopup(MouseEvent e) {
    if (e.isPopupTrigger()) {
      selected_text = ta.getSelectedText();
      if (selected_text == null) {
        menuItemFollowSelectedPointer.setEnabled(false);
      } else {
        menuItemFollowSelectedPointer.setEnabled(true);
      }
      popup.show(e.getComponent(),
            e.getX(), e.getY());
    }
  }
}

代码示例来源:origin: robo-code/robocode

public String getSelectedText() {
  return getTextPane().getSelectedText();
}

代码示例来源:origin: org.rwshop/org.rwshop.swing.speech

private void btnSpeakSelectedActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSpeakSelectedActionPerformed
  String txt = txtSpeech.getSelectedText();
  if(txt == null || txt.isEmpty()){
    txt = txtSpeech.getText();
  }
  speak(txt);
}//GEN-LAST:event_btnSpeakSelectedActionPerformed

代码示例来源:origin: omegat-org/omegat

public String getSelectedText() {
  return m_txtScriptEditor.getTextArea().getSelectedText();
}

代码示例来源:origin: mvetsch/JWT4B

public String getSelectedData() {
  return getOutputfield().getSelectedText();
}

代码示例来源:origin: codeka/wwmmo

private Template.BaseTemplate getTemplate() throws TemplateException {
 String xml = templateXml.getSelectedText();
 if (xml == null || xml.trim().equals("")) {
  xml = templateXml.getText();
 }
 Template tmpl;
 try {
  tmpl = Template.parse(new ByteArrayInputStream(xml.getBytes("utf-8")));
 } catch (UnsupportedEncodingException e) {
  throw new TemplateException("Unsupported encoding!");
 }
 return tmpl.getTemplate();
}

代码示例来源:origin: de.mhus.lib/mhu-lib-core

static public String getSelectedPart(JTextArea text) {
  String s = text.getSelectedText();
  if (s == null) {
    s = text.getText();
    int start = s.lastIndexOf("\n\n", text.getCaretPosition());
    if (start < 0)
      start = 0;
    else
      start += 2;
    int end = s.indexOf("\n\n", text.getCaretPosition());
    if (end < 0)
      end = s.length();
    s = s.substring(start, end);
    if (s == null)
      s = text.getText();
  }
  return s;
}

代码示例来源:origin: stackoverflow.com

JTextArea textArea = new JTextArea("some text");
int start = textArea.getSelectionStart();
int end = textArea.getSelectionEnd();
String replace = textArea.getSelectedText().toUpperCase();
textArea.replaceRange(replace, start, end);

代码示例来源:origin: RPTools/maptool

public void actionPerformed(ActionEvent e) {
    String selectedText = source.getSelectedText();
    if (selectedText == null) {
      selectedText = source.getText();
    }
    // TODO: Combine this with the code in MacroButton
    JTextComponent commandArea = MapTool.getFrame().getCommandPanel().getCommandTextArea();
    commandArea.setText(commandArea.getText() + selectedText);
    commandArea.requestFocusInWindow();
  }
});

代码示例来源:origin: raydac/netbeans-mmd-plugin

private void buttonBrowseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonBrowseActionPerformed
 final String selectedText = this.editorPane.getSelectedText().trim();
 try {
  UiUtils.browseURI(URI.create(selectedText), false);
 } catch (Exception ex) {
  LOGGER.error("Can't open link : " + selectedText); //NOI18N
  DialogProviderManager.getInstance().getDialogProvider().msgError(null, "Can't browse link : " + selectedText);
 }
}//GEN-LAST:event_buttonBrowseActionPerformed

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

/**
 * Block comment or uncomment the selected text in the given script panel.
 *
 * @param scriptPanel Script panel
 */
public static void blockCommentOrUncomment(JTextArea scriptPanel) {
  if (scriptPanel.getSelectedText() != null) {
    if (alreadyBlockCommented(scriptPanel)) {
      blockUncomment(scriptPanel);
    } else {
      blockComment(scriptPanel);
    }
  }
}

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

/**
 * Block comment the selected text in the given script panel.
 *
 * @param scriptPanel Script panel
 */
private static void blockComment(JTextArea scriptPanel) {
  // Recover the index of the start of the selection.
  final int startOffset = scriptPanel.getSelectionStart();
  // Comment the selection.
  final String commentedSelection = BLOCK_COMMENT_START
      + scriptPanel.getSelectedText() + BLOCK_COMMENT_END;
  scriptPanel.replaceSelection(commentedSelection);
  // Select the commented selection.
  scriptPanel.setSelectionStart(startOffset);
  scriptPanel.setSelectionEnd(startOffset + commentedSelection.length());
}

代码示例来源:origin: RPTools/maptool

public void actionPerformed(ActionEvent e) {
    String selectedText = source.getSelectedText();
    if (selectedText == null) {
      selectedText = source.getText();
    }
    // TODO: Combine this with the code in MacroButton
    JTextComponent commandArea = MapTool.getFrame().getCommandPanel().getCommandTextArea();
    commandArea.setText("/emit " + selectedText);
    commandArea.requestFocusInWindow();
    MapTool.getFrame().getCommandPanel().commitCommand();
  }
});

相关文章

JTextArea类方法