2つのJEditorPaneを使用して、テキストを1つから別のJEditorPaneに転送します。
データを転送したら、次のようにします。
JEditorPane.setText(null);
JEditorPane.setCaretPosition(0);
ただし、添付の画像からわかるように、リターンアクションにより、プロンプトが1行下に表示されます。どうすればこれを修正できますか?
編集:次はあなたにとって正しいと思われますか?もしそうなら、なぜキャレットは自分自身をキャラクター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);
}
}
}