本文整理了Java中javax.swing.JTextPane.getSelectedText()
方法的一些代码示例,展示了JTextPane.getSelectedText()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JTextPane.getSelectedText()
方法的具体详情如下:
包路径:javax.swing.JTextPane
类名称:JTextPane
方法名:getSelectedText
暂无
代码示例来源:origin: omegat-org/omegat
/**
* Get the currently selected text in the search results pane
*
* @return Selected text, or {@code null} if none
*/
public String getViewerSelection() {
return form.m_viewer.getSelectedText();
}
代码示例来源:origin: triplea-game/triplea
@Override
public void mouseReleased(final MouseEvent e) {
final String markedText = text.getSelectedText();
if (markedText == null || markedText.length() == 0) {
nextMessage.requestFocusInWindow();
}
}
代码示例来源:origin: blurpy/kouchat
@Override
public void popupMenuWillBecomeVisible(final PopupMenuEvent e) {
if (textpane.getSelectedText() == null) {
copyMI.setEnabled(false);
} else {
copyMI.setEnabled(true);
}
if (textpane.getText().length() == 0) {
selectAllMI.setEnabled(false);
} else {
selectAllMI.setEnabled(true);
}
}
代码示例来源:origin: com.itextpdf/itext-rups
public void actionPerformed(ActionEvent e) {
boolean nothingSelected = false;
JTextPane textPane = (JTextPane) invoker;
if (textPane.getSelectedText() == null || textPane.getSelectedText().trim().length() == 0) {
nothingSelected = true;
textPane.selectAll();
}
textPane.copy();
if (nothingSelected) {
textPane.select(0, 0);
}
}
代码示例来源:origin: edu.utah.bmi.nlp/nlp-core
public void keyPressed(KeyEvent ke) {
if (ke != null && ke.getKeyCode() == KeyEvent.VK_C &&
(ke.getModifiers() & KeyEvent.CTRL_MASK) != 0) {
String selection = textPane.getSelectedText();
if (selection != null && selection.length() > 0) {
Clipboard clipboard = getToolkit().getSystemClipboard();
if (clipboard != null) {
StringSelection data = new StringSelection(selection);
clipboard.setContents(data, data);
}
}
}
}
代码示例来源:origin: org.apache.uima/uimaj-tools
@Override
public void keyPressed(KeyEvent ke) {
if (ke != null && ke.getKeyCode() == KeyEvent.VK_C &&
(ke.getModifiers() & InputEvent.CTRL_MASK) != 0) {
String selection = textPane.getSelectedText();
if (selection != null && selection.length() > 0) {
Clipboard clipboard = getToolkit().getSystemClipboard();
if (clipboard != null) {
StringSelection data = new StringSelection(selection);
clipboard.setContents(data, data);
}
}
}
}
代码示例来源:origin: com.itextpdf/itext-rups
JTextPane textPane = (JTextPane) invoker;
if (textPane.getSelectedText() == null || textPane.getSelectedText().trim().length() == 0) {
nothingSelected = true;
textPane.selectAll();
writer.write(textPane.getSelectedText());
代码示例来源:origin: stackoverflow.com
jTextPane1.addCaretListener(new CaretListener() {
public void caretUpdate(CaretEvent evt) {
if(evt.getDot() == evt.getMark())return;
JTextPane txtPane = (JTextPane) evt.getSource();
DefaultHighlighter highlighter = (DefaultHighlighter) txtPane.getHighlighter();
highlighter.removeAllHighlights();
DefaultHighlightPainter hPainter = new DefaultHighlightPainter(new Color(0xFFAA00));
String selText = txtPane.getSelectedText();
String contText = "";// = jTextPane1.getText();
DefaultStyledDocument document = (DefaultStyledDocument) txtPane.getDocument();
try {
contText = document.getText(0, document.getLength());
} catch (BadLocationException ex) {
Logger.getLogger(JTextPaneTest.class.getName()).log(Level.SEVERE, null, ex);
}
int index = 0;
while((index = contText.indexOf(selText, index)) > -1){
try {
highlighter.addHighlight(index, selText.length()+index, hPainter);
index = index + selText.length();
} catch (BadLocationException ex) {
Logger.getLogger(JTextPaneTest.class.getName()).log(Level.SEVERE, null, ex);
//System.out.println(index);
}
}
}
});
代码示例来源:origin: org.owasp.jbrofuzz/jbrofuzz
/**
* <p>
* Method for adding a fuzzer in the payloads table.
* </p>
*/
@Override
public void add() {
// Check to see what text has been selected
try {
requestPane.getSelectedText();
} catch (final IllegalArgumentException e) {
JOptionPane
.showInputDialog(
this,
"An exception was thrown while attempting to get the selected text",
"Add Fuzzer", JOptionPane.ERROR_MESSAGE);
}
// Find the location of where the text has been selected
final int sPoint = requestPane.getSelectionStart();
final int fPoint = requestPane.getSelectionEnd();
new PayloadsDialog(this, sPoint, fPoint);
}
代码示例来源:origin: zolyfarkas/spf4j
/**
* Bundle up the data for export.
*/
@Nullable
protected Transferable createTransferable(JComponent c) {
javax.swing.JTextPane source = (javax.swing.JTextPane) c;
int start = source.getSelectionStart();
int end = source.getSelectionEnd();
Document doc = source.getDocument();
if (start == end) {
return null;
}
try {
p0 = doc.createPosition(start);
p1 = doc.createPosition(end);
} catch (BadLocationException e) {
throw new RuntimeException(e);
}
String data = source.getSelectedText();
return new StringSelection(data);
}
代码示例来源:origin: otros-systems/otroslogviewer
@Override
protected void actionPerformedHook(ActionEvent e) {
String selectedText = logDetailTextArea.getSelectedText();
if (logDetailTextArea.getSelectionStart() == logDetailTextArea.getSelectionEnd()) {
selectedText = logDetailTextArea.getText();
}
ClipboardUtil.copyToClipboard(selectedText);
}
}
代码示例来源:origin: stackoverflow.com
int start = bold.getSelectionStart();
int end = bold.getSelectionEnd();
String txt = bold.getSelectedText();
if(end != start)
try {
代码示例来源:origin: org.fudaa.framework.ctulu/ctulu-ui
public void actionPerformed(ActionEvent ae) {
JTextPane parentTextPane = parentEkit.getTextPane();
String selText = parentTextPane.getSelectedText();
int textLength = -1;
if (selText != null) {
textLength = selText.length();
}
if (selText == null || textLength < 1) {
return;
}
JEditorPane editor = getEditor(ae);
if (editor != null) {
StyledEditorKit kit = getStyledEditorKit(editor);
MutableAttributeSet attr = kit.getInputAttributes();
boolean newValue = (attr.getAttribute(htmlTag) == Boolean.TRUE) ? false : true;
SimpleAttributeSet sas = new SimpleAttributeSet();
sas.addAttribute(htmlTag, Boolean.valueOf(newValue));
//StyleConstants.setUnderline(sas, newValue);
setCharacterAttributes(editor, sas, false);
}
}
}
代码示例来源:origin: org.fudaa.framework.ctulu/ctulu-ui
public void actionPerformed(ActionEvent ae)
{
if(this.name.equals("[EKITFONTSELECTOR]"))
{
StyledEditorKit.FontFamilyAction newFontFamilyAction = new StyledEditorKit.FontFamilyAction("fontFamilyAction", parentEkit.getFontNameFromSelector());
newFontFamilyAction.actionPerformed(ae);
}
else
{
FontSelectorDialog fsdInput = new FontSelectorDialog(parentEkit.getFrame(), Translatrix.getTranslationString("FontDialogTitle"), true, "face", parentEkit.getTextPane().getSelectedText());
String newFace = fsdInput.getFontName();
if(newFace != null)
{
StyledEditorKit.FontFamilyAction newFontFamilyAction = new StyledEditorKit.FontFamilyAction("fontFamilyAction", newFace);
newFontFamilyAction.actionPerformed(ae);
}
}
}
}
代码示例来源:origin: com.davidbracewell/hermes-core
private void addTag(Tag tag) {
int start = editorPane.getSelectionStart();
int end = editorPane.getSelectionEnd();
if (annotationTableModel.spanHasAnnotation(start, end)) {
if (JOptionPane.showConfirmDialog(null, "Delete existing annotations on span?") == JOptionPane.OK_OPTION) {
annotationTableModel.annotations.overlapping(new Span(start, end)).forEach(a -> {
int r = annotationTableModel.find(a.start(), a.end());
annotationTableModel.removeRow(r);
});
} else {
return;
}
}
if (start == end) {
return;
}
dirty = true;
editorPane.getStyledDocument()
.setCharacterAttributes(start, end - start, editorPane.getStyle(tag.name()), true);
annotationTableModel.addRow(new Object[]{start, end, tag, editorPane.getSelectedText()});
}
代码示例来源:origin: org.fudaa.framework.ctulu/ctulu-ui
String selText = parentTextPane.getSelectedText();
int textLength = -1;
if(selText != null)
代码示例来源:origin: beanshell/beanshell
if (text.getSelectedText() == null) {
if ( (e.getModifiersEx() & InputEvent.CTRL_DOWN_MASK) > 0
&& e.getID() == KeyEvent.KEY_PRESSED )
代码示例来源:origin: org.fudaa.framework.ctulu/ctulu-ui
SimpleAttributeSet sasText = new SimpleAttributeSet(parentTextPane.getCharacterAttributes());
SimpleAttributeSet sasPara = new SimpleAttributeSet(parentTextPane.getParagraphAttributes());
String selText = parentTextPane.getSelectedText();
int textLength = -1;
代码示例来源:origin: mars-sim/mars-sim
public void setUpMouseCopyKey() {
terminal.registerHandler("ctrl C", t -> {
t.getTextPane().copy();
return new ReadHandlerData(ReadInterruptionStrategy.Action.CONTINUE);
});
terminal.registerHandler("ctrl V", t -> {
// t.getTextPane().paste();
String selectedText = t.getTextPane().getSelectedText();
if(selectedText != null) {
t.getTextPane().setCaretPosition(t.getDocument().getLength());
t.appendToInput(selectedText, false);
}
return new ReadHandlerData(ReadInterruptionStrategy.Action.CONTINUE);
});
}
代码示例来源:origin: org.fudaa.framework.ctulu/ctulu-ui
try {
if (pos > 0) {
if ((selectedText = jtpMain.getSelectedText()) != null) {
htmlUtilities.delete();
return;
内容来源于网络,如有侵权,请联系作者删除!