在Java中使用cut()方法 [英] Using the cut() method in java

查看:354
本文介绍了在Java中使用cut()方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在Java中实现cut方法以提供剪切和粘贴功能。我已经使用StringSelection和getSystemClipboard()提供了剪切功能(下面的代码),但是我想知道如何使用Java的内置方法。 cut()方法。
用于剪切功能的代码。

I would like to implement the cut method in java to provide the cut and paste functionality.I have already used StringSelection and getSystemClipboard() to provide the cut functionality(code below),but I wanna know how I can use java's inbuilt cut() method for it. Code for cut functionality.

String t = qu.getText();
        StringSelection s = new StringSelection(t);
        this.getToolkit().getSystemClipboard().setContents(s, s);
        qu.setText("");

我期望这样的方法可以工作,但是没有用

I expected something like this to work but it didn't

        qu.cut();

预先感谢。

推荐答案

这是因为cut()方法需要在文本字段中进行选择。尝试以下代码:

It is because cut() method requires a selection in the text field. Try the following code:

qu.selectAll();
qu.cut();

这篇关于在Java中使用cut()方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆