ChatGUI
我正在使用2 JEditorPane将文本从一个传输到另一个。
一旦我传输了数据,我将执行以下操作:
JEditorPane.setText(null);
JEditorPane.setCaretPosition(0);但是,正如您从附加的图像中看到的,返回操作会使提示符出现在下一行。我该如何解决这个问题呢?
编辑:以下内容对你来说是正确的吗?如果是这样,那么为什么插入符号不将自己定位到chracter 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);
}
}
}发布于 2010-04-27 04:53:56
代码运行后,JEditorPane会以通常的方式对Enter键做出反应,即插入一个换行符。尝试调用ke.consume()来“消费”该事件,这样JEditorPane本身就不会处理它。
发布于 2010-04-27 10:20:13
不要使用KeyListener。您应该使用自定义操作。这样,您就可以替换默认的Action。阅读Key Bindings上的内容。
https://stackoverflow.com/questions/2716256
复制相似问题