Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/338.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java绝地窗格_Java_Jeditorpane - Fatal编程技术网

Java绝地窗格

Java绝地窗格,java,jeditorpane,Java,Jeditorpane,我正在使用2个窗格将文本从一个窗格传输到另一个窗格 传输数据后,我将执行以下操作: JEditorPane.setText(null); JEditorPane.setCaretPosition(0); 但正如您从所附的图像中看到的,返回操作使提示符向下显示一行。我怎样才能解决这个问题 编辑:您认为以下内容正确吗?如果是这样,为什么插入符号不将自身定位到字符0位置 private class MyKeyAdapter extends KeyAdapter { @Overri

我正在使用2个窗格将文本从一个窗格传输到另一个窗格

传输数据后,我将执行以下操作:

JEditorPane.setText(null);

JEditorPane.setCaretPosition(0);
但正如您从所附的图像中看到的,返回操作使提示符向下显示一行。我怎样才能解决这个问题

编辑:您认为以下内容正确吗?如果是这样,为什么插入符号不将自身定位到字符0位置

    private class MyKeyAdapter extends KeyAdapter {

    @Override
    public void keyPressed(KeyEvent ke) {

        int kc = ke.getKeyCode();

        if (kc == ke.VK_ENTER) {

            System.out.println(editorPaneHistory.getText());

            System.out.println(editorPaneHomeText.getText());

            editorPaneHistory.setText(editorPaneHomeText.getText());

            //JEditorPane - editorPaneHistory
            //JEditorPane - editorPaneHomeText

            editorPaneHomeText.setText(null);

            editorPaneHomeText.setCaretPosition(0);

        }
    }
}

代码运行后,JEditorPane将以通常的方式对enter键作出反应,即插入新行。尝试调用
ke.consume()
来“消费”事件,以便JEditorPane本身不会处理它。

不要使用KeyListener。您应该使用自定义操作。这样可以替换默认操作。请继续阅读。

我尝试过这个,但我的插入符号在“清理”后消失了,当我点击我创建的“绝地武士”窗格时,插入符号会出现在顶部。也许还有什么不对劲的地方你可以分享你的例子吗?你说的“清理”是什么意思?你在做我不做的事吗?能举个小例子吗?在我的尝试中,当我放置ke.consume()时;“回车”停止响应。忘记提及。一旦我正确地定位了.consume(),它的性能就完美无缺了!谢谢