本文整理汇总了Java中javax.swing.text.JTextComponent.copy方法的典型用法代码示例。如果您正苦于以下问题:Java JTextComponent.copy方法的具体用法?Java JTextComponent.copy怎么用?Java JTextComponent.copy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.text.JTextComponent
的用法示例。
在下文中一共展示了JTextComponent.copy方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: actionPerformed
import javax.swing.text.JTextComponent; //导入方法依赖的package包/类
@Override
public void actionPerformed(ActionEvent evt, JTextComponent target) {
if (target != null) {
try {
Caret caret = target.getCaret();
boolean emptySelection = false;
boolean disableNoSelectionCopy =
Boolean.getBoolean("org.netbeans.editor.disable.no.selection.copy");
int caretPosition = caret.getDot();
if(!disableNoSelectionCopy &&
(!(caret instanceof EditorCaret)) || !(((EditorCaret)caret).getCarets().size() > 1)) {
emptySelection = !Utilities.isSelectionShowing(target);
// If there is no selection then pre-select a current line including newline
if (emptySelection && !disableNoSelectionCopy) {
Element elem = ((AbstractDocument) target.getDocument()).getParagraphElement(
caretPosition);
if (!Utilities.isRowWhite((BaseDocument) target.getDocument(), elem.getStartOffset())) {
target.select(elem.getStartOffset(), elem.getEndOffset());
}
}
}
target.copy();
if (emptySelection && !disableNoSelectionCopy) {
target.setCaretPosition(caretPosition);
}
} catch (BadLocationException ble) {
LOG.log(Level.FINE, null, ble);
}
}
}
示例2: actionPerformed
import javax.swing.text.JTextComponent; //导入方法依赖的package包/类
public void actionPerformed(ActionEvent e) {
JTextComponent tc = (JTextComponent) getInvoker();
String sel = tc.getSelectedText();
if (e.getSource() == cutItem) {
tc.cut();
} else if (e.getSource() == copyItem) {
tc.copy();
} else if (e.getSource() == pasteItem) {
tc.paste();
} else if (e.getSource() == selectAllItem) {
tc.selectAll();
} else if (e.getSource() == deleteItem) {
Document doc = tc.getDocument();
int start = tc.getSelectionStart();
int end = tc.getSelectionEnd();
try {
Position p0 = doc.createPosition(start);
Position p1 = doc.createPosition(end);
if ((p0 != null) && (p1 != null)
&& (p0.getOffset() != p1.getOffset())) {
doc.remove(p0.getOffset(), p1.getOffset() - p0.getOffset());
}
} catch (BadLocationException be) {
}
}
}