本文整理了Java中javax.swing.JEditorPane.getSelectedText()
方法的一些代码示例,展示了JEditorPane.getSelectedText()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JEditorPane.getSelectedText()
方法的具体详情如下:
包路径:javax.swing.JEditorPane
类名称:JEditorPane
方法名:getSelectedText
暂无
代码示例来源:origin: igniterealtime/Spark
/**
* Returns the selected text contained in this TextComponent. If the selection is null or the document empty, returns null.
*
* @return the text.
*/
public String getSelectedText() {
return browser.getSelectedText();
}
代码示例来源:origin: freeplane/freeplane
@Override
public String getSelectedText() {
final String selectedText = super.getSelectedText();
return selectedText != null ? selectedText.replace('\u00a0', ' ') : null;
}
代码示例来源:origin: ATLauncher/ATLauncher
@Override
public void actionPerformed(ActionEvent e) {
StringSelection text = new StringSelection(NEWS_PANE.getSelectedText());
Toolkit.getDefaultToolkit().getSystemClipboard().setContents(text, null);
}
});
代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-cnd-debugger-common2
public static String getCurrentSelection() {
JEditorPane ep = getCurrentEditor(null);
if (ep == null)
return null;
String s = ep.getSelectedText();
if (s == null)
return null;
return s;
}
代码示例来源:origin: omegat-org/omegat
/**
* Remove invisible direction chars on the copy text into clipboard.
*/
@Override
public String getSelectedText() {
String st = super.getSelectedText();
return st != null ? EditorUtils.removeDirectionChars(st) : null;
}
代码示例来源:origin: org.jspresso.framework/jspresso-swing-components
/**
* {@inheritDoc}
*/
@Override
protected Transferable createTransferable(JComponent c) {
String text = detailsPane.getSelectedText();
if (text == null || text.equals("")) {
detailsPane.selectAll();
text = detailsPane.getSelectedText();
detailsPane.select(-1, -1);
}
return new StringSelection(text);
}
}
代码示例来源:origin: org.jspresso/jspresso-swing-components
/**
* {@inheritDoc}
*/
@Override
protected Transferable createTransferable(@SuppressWarnings("unused")
JComponent c) {
String text = detailsPane.getSelectedText();
if (text == null || text.equals("")) {
detailsPane.selectAll();
text = detailsPane.getSelectedText();
detailsPane.select(-1, -1);
}
return new StringSelection(text);
}
}
代码示例来源:origin: io.ultreia.java4all.jaxx/jaxx-widgets-extra
@Override
public void mouseClicked(MouseEvent e) {
JEditorPane textArea = (JEditorPane) e.getSource();
final String selectedText = textArea.getSelectedText();
if (e.getButton() == MouseEvent.BUTTON3 && !StringUtils.isBlank(selectedText)) {
JPopupMenu popupMenu = new JPopupMenu();
Icon copyIcon = Resource.getIcon(COPY_ICON_PATH);
JMenuItem copyMenuItem = new JMenuItem(t("nuitonwidgets.common.copy"), copyIcon);
copyMenuItem.addActionListener(e1 -> {
StringSelection selection = new StringSelection(selectedText);
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
clipboard.setContents(selection, null);
});
popupMenu.add(copyMenuItem);
popupMenu.show(textArea, e.getX(), e.getY());
}
}
});
代码示例来源:origin: org.nuiton/nuiton-widgets
@Override
public void mouseClicked(MouseEvent e) {
JEditorPane textArea = (JEditorPane)e.getSource();
final String selectedText = textArea.getSelectedText();
if (e.getButton() == MouseEvent.BUTTON3 && !StringUtils.isBlank(selectedText)) {
JPopupMenu popupMenu = new JPopupMenu();
Icon copyIcon = Resource.getIcon(COPY_ICON_PATH);
JMenuItem copyMenuItem = new JMenuItem(_("nuitonwidgets.common.copy"), copyIcon);
copyMenuItem.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
StringSelection selection = new StringSelection(selectedText);
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
clipboard.setContents(selection, null);
}
});
popupMenu.add(copyMenuItem);
popupMenu.show(textArea, e.getX(), e.getY());
}
}
});
代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-cnd-debugger-common2
private static String getSelectedExpr(JEditorPane ep, int offset) {
if ((ep.getSelectionStart() <= offset) && (offset <= ep.getSelectionEnd())) {
return ep.getSelectedText();
}
return null;
}
代码示例来源:origin: net.imagej/ij
public void keyPressed(KeyEvent e) {
int keyCode = e.getKeyCode();
ij.IJ.setKeyDown(keyCode);
escapePressed = keyCode==KeyEvent.VK_ESCAPE;
if (keyCode==KeyEvent.VK_C) {
if (editorPane.getSelectedText()==null || editorPane.getSelectedText().length()==0)
editorPane.selectAll();
editorPane.copy();
editorPane.select(0,0);
} else if (keyCode==KeyEvent.VK_ENTER || keyCode==KeyEvent.VK_W || escapePressed)
dispose();
}
代码示例来源:origin: imagej/ImageJA
public void keyPressed(KeyEvent e) {
int keyCode = e.getKeyCode();
ij.IJ.setKeyDown(keyCode);
escapePressed = keyCode==KeyEvent.VK_ESCAPE;
if (keyCode==KeyEvent.VK_C) {
if (editorPane.getSelectedText()==null || editorPane.getSelectedText().length()==0)
editorPane.selectAll();
editorPane.copy();
editorPane.select(0,0);
} else if (keyCode==KeyEvent.VK_ENTER || keyCode==KeyEvent.VK_W || escapePressed)
dispose();
}
代码示例来源:origin: dcaoyuan/nbscala
/**
* Returns identifier currently selected in editor or <code>null</code>.
*
* @return identifier currently selected in editor or <code>null</code>
*/
@Override
public String getSelectedIdentifier() {
JEditorPane ep = contextDispatcher.getCurrentEditor();
if (ep == null) {
return null;
}
String s = ep.getSelectedText();
if (s == null) {
return null;
}
if (Utilities.isJavaIdentifier(s)) {
return s;
}
return null;
}
代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-debugger-jpda-projects
/**
* Returns identifier currently selected in editor or <code>null</code>.
*
* @return identifier currently selected in editor or <code>null</code>
*/
@Override
public String getSelectedIdentifier () {
JEditorPane ep = contextDispatcher.getCurrentEditor ();
if (ep == null) {
return null;
}
String s = ep.getSelectedText ();
if (s == null) {
return null;
}
if (Utilities.isJavaIdentifier (s)) {
return s;
}
return null;
}
代码示例来源:origin: robo-code/robocode
public void doReplacement() {
EditWindow currentWindow = editor.getActiveWindow();
if (currentWindow == null || getFindTextField().getText().length() == 0) {
// launch error dialog?
return;
}
JEditorPane editorPane = currentWindow.getEditorPane();
String text = editorPane.getSelectedText();
if (text == null) {
// no selection
return;
}
Matcher m = getCurrentPattern().matcher(text);
if (m.matches()) {
String replacement = getReplaceTextField().getText();
if (getRegexButton().isSelected()) {
replacement = m.replaceFirst(replacement);
}
editorPane.replaceSelection(replacement);
}
}
代码示例来源:origin: stackoverflow.com
ClipboardService cs = (ClipboardService)ServiceManager.lookup
("javax.jnlp.ClipboardService");
StringSelection transferable = new StringSelection(editor.getSelectedText());
cs.setContents(transferable);
} catch (Exception e1) {
代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-debugger-jpda-projectsui
/**
* Returns identifier currently selected in editor or <code>null</code>.
*
* @return identifier currently selected in editor or <code>null</code>
*/
@Override
public String getSelectedIdentifier () {
JEditorPane ep = contextDispatcher.getCurrentEditor ();
if (ep == null) {
return null;
}
Caret caret = ep.getCaret();
if (caret == null) {
// No caret => no selected text
return null;
}
String s = ep.getSelectedText ();
if (s == null) {
return null;
}
if (Utilities.isJavaIdentifier (s)) {
return s;
}
return null;
}
代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-web-debug
public static String getJavaIdentifier(StyledDocument doc, JEditorPane ep, int offset) {
String t = null;
if ( (ep.getSelectionStart() <= offset) && (offset <= ep.getSelectionEnd())) {
t = ep.getSelectedText();
代码示例来源:origin: dcaoyuan/nbscala
if ( (ep.getSelectionStart () <= offset) &&
(offset <= ep.getSelectionEnd ())
) t = ep.getSelectedText ();
if (t != null) return t;
代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-debugger-jpda-projectsui
currentOffset = 0;
} else {
s = ep.getSelectedText ();
currentOffset = ep.getCaretPosition();
if (ep.getSelectionStart() > currentOffset || ep.getSelectionEnd() < currentOffset) {
内容来源于网络,如有侵权,请联系作者删除!