在同一个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中选择文本!

最佳答案

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


但是当JEditorPane未被关注时,选择是不可见的

使其可见

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

10-01 21:01