javax.swing.text.JTextComponent#cut ( )源码实例Demo

下面列出了javax.swing.text.JTextComponent#cut ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: NSS   文件: TextComponentPopupMenu.java
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) {
		}
	}
}
 
源代码2 项目: finalspeed-91yun   文件: TextComponentPopupMenu.java
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) {
		}
	}
}
 
源代码3 项目: ermasterr   文件: CustomCellEditor.java
@Override
public void actionPerformed(final ActionEvent e) {
    final JTextComponent target = getTextComponent(e);
    if (target != null) {
        target.cut();
    }
}
 
源代码4 项目: finalspeed   文件: TextComponentPopupMenu.java
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) {
        }
    }
}
 
源代码5 项目: spotbugs   文件: MainFrameMenu.java
@Override
public void actionPerformed(ActionEvent evt) {
    JTextComponent text = getTextComponent(evt);

    if (text == null) {
        return;
    }

    text.cut();
}
 
源代码6 项目: erflute   文件: CustomCellEditor.java
@Override
public void actionPerformed(ActionEvent e) {
    final JTextComponent target = getTextComponent(e);
    if (target != null) {
        target.cut();
    }
}
 
源代码7 项目: xtunnel   文件: TextComponentPopupMenu.java
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) {
		}
	}
}
 
源代码8 项目: ermaster-b   文件: CustomCellEditor.java
public void actionPerformed(ActionEvent e) {
	JTextComponent target = getTextComponent(e);
	if (target != null) {
		target.cut();
	}
}