本文整理了Java中javax.swing.text.JTextComponent.getSelectedText()
方法的一些代码示例,展示了JTextComponent.getSelectedText()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JTextComponent.getSelectedText()
方法的具体详情如下:
包路径:javax.swing.text.JTextComponent
类名称:JTextComponent
方法名:getSelectedText
暂无
代码示例来源:origin: skylot/jadx
private void process(MouseEvent e) {
textComponent.requestFocus();
boolean enabled = textComponent.isEnabled();
boolean editable = textComponent.isEditable();
boolean nonempty = !(textComponent.getText() == null || textComponent.getText().equals(""));
boolean marked = textComponent.getSelectedText() != null;
boolean pasteAvailable = Toolkit.getDefaultToolkit().getSystemClipboard()
.getContents(null).isDataFlavorSupported(DataFlavor.stringFlavor);
undoAction.setEnabled(enabled && editable && undoManager.canUndo());
redoAction.setEnabled(enabled && editable && undoManager.canRedo());
cutAction.setEnabled(enabled && editable && marked);
copyAction.setEnabled(enabled && marked);
pasteAction.setEnabled(enabled && editable && pasteAvailable);
deleteAction.setEnabled(enabled && editable && marked);
selectAllAction.setEnabled(enabled && nonempty);
int nx = e.getX();
if (nx > 500) {
nx = nx - popup.getSize().width;
}
popup.show(e.getComponent(), nx, e.getY() - popup.getSize().height);
}
}
代码示例来源:origin: RipMeApp/ripme
boolean editable = textComponent.isEditable();
boolean nonempty = !(textComponent.getText() == null || textComponent.getText().equals(""));
boolean marked = textComponent.getSelectedText() != null;
代码示例来源:origin: groovy/groovy-core
pos += textComponent.getSelectedText() == null ?
(backwards ? -1 : 1) : 0;
代码示例来源:origin: groovy/groovy-core
findReplaceCount = 0;
int pos = textComponent.getSelectedText() == null ?
textComponent.getCaretPosition() :
textComponent.getSelectionStart();
代码示例来源:origin: groovy/groovy-core
findReplaceCount = 0;
int last = textComponent.getSelectedText() == null ?
textComponent.getCaretPosition() :
textComponent.getSelectionStart();
代码示例来源:origin: groovy/groovy-core
public void actionPerformed(ActionEvent ae) {
lastAction = FIND_ACTION_COMMAND;
findReplaceCount = 0;
if (FIND_REPLACE_DIALOG.isVisible() &&
FIND_REPLACE_DIALOG.getTitle().equals(FIND_ACTION_COMMAND)) {
}
int pos = textComponent.getSelectedText() == null ?
textComponent.getCaretPosition() :
textComponent.getSelectionStart();
boolean reverse = (ae.getModifiers() & ActionEvent.SHIFT_MASK) != 0;
pos = findNext(reverse, pos);
if (pos > -1) {
String pattern = (String) FIND_FIELD.getSelectedItem();
textComponent.select(pos, pos + pattern.length());
findReplaceCount = 1;
}
setListStrings();
fireTextEvent();
}
}
代码示例来源:origin: stackoverflow.com
boolean editable = textComponent.isEditable();
boolean nonempty = !(textComponent.getText() == null || textComponent.getText().equals(""));
boolean marked = textComponent.getSelectedText() != null;
代码示例来源:origin: groovy/groovy-core
FIND_REPLACE_DIALOG.setTitle(title);
String text = textComponent.getSelectedText();
if (text == null) {
text = "";
代码示例来源:origin: stackoverflow.com
text = tarea.getSelectedText();
if (text != null && text.length() > 0)
代码示例来源:origin: bobbylight/RSyntaxTextArea
TextTransferable(JTextComponent c, int start, int end) {
this.c = c;
Document doc = c.getDocument();
try {
p0 = doc.createPosition(start);
p1 = doc.createPosition(end);
plainData = c.getSelectedText();
} catch (BadLocationException ble) {
}
}
代码示例来源:origin: stackoverflow.com
else if (choice == cutI)
pad = ta.getSelectedText();
ta.replaceRange("", ta.getSelectionStart(), ta.getSelectionEnd());
pad = ta.getSelectedText();
else if (choice == pasteI)
ta.insert(pad, ta.getCaretPosition());
代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-visualweb-designer
public Transferable copyText(boolean cut) {
String text = inlineTextEditor.getSelectedText();
Transferable transferable = new StringSelection(text);
if (cut) {
inlineTextEditor.replaceSelection("");
}
return transferable;
}
代码示例来源:origin: stackoverflow.com
public void MouseClicked(MouseEvent me) {
if(me.getButton() == MouseEvent.BUTTON2) {
// This is the code you probably don't have yet
// You may have to check this cast
JTextComponent myComponent = (JTextComponent) me.getComponent();
if (myComponent.getSelectedText() != null) {
JPopupMenu theMenu = myComponent.getComponentPopupMenu();
// Etc... you wrote this part already and said it works
}
}
}
代码示例来源:origin: stackoverflow.com
Action logSelected = new TextAction("log selected") {
@Override
public void actionPerformed(ActionEvent e) {
JTextComponent text = getTextComponent(e);
System.out.println("selected: " + text.getSelectedText());
}
};
JComponent content = new JPanel();
content.add(new JTextField("sometext", 20));
content.add(new JTextField("other content", 20));
content.add(new JCheckBox("just some focusable comp"));
content.add(new JButton(logSelected));
代码示例来源:origin: org.codehaus.jtstand/jtstand-editor
TextTransferable(JTextComponent c, int start, int end) {
this.c = c;
Document doc = c.getDocument();
try {
p0 = doc.createPosition(start);
p1 = doc.createPosition(end);
plainData = c.getSelectedText();
} catch (BadLocationException ble) {
}
}
代码示例来源:origin: com.github.arnabk/pgslookandfeel
public boolean isEnabled() {
return comp.isEditable()
&& comp.isEnabled()
&& comp.getSelectedText() != null;
}
}
代码示例来源:origin: de.sciss/syntaxpane
/**
* Replaces single occurrence of match with the replacement.
*/
public void doReplace(JTextComponent target, String replacement) {
if (target.getSelectedText() != null) {
target.replaceSelection(replacement == null ? "" : replacement);
doFindNext(target,true);
}
}
代码示例来源:origin: net.sf.squirrel-sql.thirdparty-non-maven/org-netbeans-modules-editor-lib
private void updateSystemSelection() {
if (!jdk14){
return;
}
if (getDot() != getMark() && component != null) {
Clipboard clip = getSystemSelection();
if (clip != null) {
clip.setContents(new java.awt.datatransfer.StringSelection(component.getSelectedText()), null);
}
}
}
代码示例来源:origin: omegat-org/omegat
private String getTrimmedSelectedTextInMainWindow() {
String selection = null;
Component component = mainWindow.getMostRecentFocusOwner();
if (component instanceof JTextComponent) {
selection = ((JTextComponent) component).getSelectedText();
if (!StringUtil.isEmpty(selection)) {
selection = EditorUtils.removeDirectionChars(selection);
selection = selection.trim();
}
}
return selection;
}
代码示例来源:origin: gaborbata/jpass
@Override
public boolean isEnabled(JTextComponent component) {
boolean copyEnabled = true;
if (component instanceof CopiablePasswordField) {
copyEnabled = ((CopiablePasswordField) component).isCopyEnabled();
}
return component != null && copyEnabled && component.isEnabled() && component.isEditable()
&& component.getSelectedText() != null;
}
}),
内容来源于网络,如有侵权,请联系作者删除!