2014-04-08 28 views
0

同样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中选择文本选择两个JEditorPane的文字!

回答

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

但当JEditorPane不是焦点的选择是不可见的

使其可见使用

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

这是行不通的! 我的问题是,当我使用鼠标为了从一个jeditorpane选择文本它工作正常,但我想从2 jeditorpane同时由鼠标选择文本! –

+0

我不明白它应该如何工作。请描述更多...还要添加为什么你需要该功能? – StanislavL

+0

在我的面板中,我有2个jeditorpane,当我运行应用程序时,我使用鼠标从eatch jeditorpane中选择文本。但我无法使用鼠标从2 jeditorpane中选择文本 –