从多个JEditorPane中选择文本

时间:2014-04-08 08:45:30

标签: java swing jeditorpane

在同一个JPanel中,我有两个JEditorPane,我如何同时从两个JEditorPane中选择文字

JPanel panel=new JPanel(new BorderLayout());
JEditorPane jeditorpane1=new JEditorPane();
// Set content of jeditorpane1
JEditorPane jeditorpane2=new JEditorPane();
// Set content of jeditorpane2
panel.add(jeditorpane1,BorderLayout.WEST);
panel.add(jeditorpane2,BorderLayout.EAST);

我用鼠标从jeditorpane中选择文字!

1 个答案:

答案 0 :(得分:1)

jeditorpane1.selectAll();
jeditorpane2.selectAll();

但是当JEditorPane没有聚焦时,选择是不可见的

使其可见使用

((DefaultCaret)jeditorpane1.getCaret()).setSelectionVisible(true);