Java Code Examples for javax.swing.text.JTextComponent#cut()
The following examples show how to use
javax.swing.text.JTextComponent#cut() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TextComponentPopupMenu.java From NSS with Apache License 2.0 | 5 votes |
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) { } } }
Example 2
Source File: TextComponentPopupMenu.java From finalspeed-91yun with GNU General Public License v2.0 | 5 votes |
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) { } } }
Example 3
Source File: CustomCellEditor.java From ermasterr with Apache License 2.0 | 5 votes |
@Override public void actionPerformed(final ActionEvent e) { final JTextComponent target = getTextComponent(e); if (target != null) { target.cut(); } }
Example 4
Source File: TextComponentPopupMenu.java From finalspeed with GNU General Public License v2.0 | 5 votes |
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 ignored) { } } }
Example 5
Source File: MainFrameMenu.java From spotbugs with GNU Lesser General Public License v2.1 | 5 votes |
@Override public void actionPerformed(ActionEvent evt) { JTextComponent text = getTextComponent(evt); if (text == null) { return; } text.cut(); }
Example 6
Source File: CustomCellEditor.java From erflute with Apache License 2.0 | 5 votes |
@Override public void actionPerformed(ActionEvent e) { final JTextComponent target = getTextComponent(e); if (target != null) { target.cut(); } }
Example 7
Source File: TextComponentPopupMenu.java From xtunnel with GNU General Public License v2.0 | 5 votes |
public void actionPerformed(ActionEvent e) { JTextComponent tc = (JTextComponent) getInvoker(); @SuppressWarnings("unused") 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) { } } }
Example 8
Source File: CustomCellEditor.java From ermaster-b with Apache License 2.0 | 4 votes |
public void actionPerformed(ActionEvent e) { JTextComponent target = getTextComponent(e); if (target != null) { target.cut(); } }