0

我有两个 Jtextpane 我想做的是从 1 个 Jtextpane 中选择文本,并且我希望它应该在选择菜单项 Edit 后出现在第二个 Jtextpane 中

我做过的

 popMenu[i].addActionListener(new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent e) {
                        String str = e.getActionCommand();
                   .....
                        if (str.equalsIgnoreCase("edit")) {
                            taSecond.setBackground(new Color(0xFBFCDD));
                            taSecond.setText(taFirst.getSelectedText());
                            System.out.println("bounds====>"+taFirst.getBounds());
                            taFirst.getBounds().setBounds(taFirst.getBounds());
                            editedText = true;

                        }
                    }
                });

现在我不知道如何将编辑后的文本放回从我得到文本的位置选择的位置谁能告诉解决方案

4

1 回答 1

0

谢谢

try {

                    doc.remove(start, end-start);
                    doc.insertString(start, str, normal);
                    editedText=false;
                } catch (BadLocationException ex) {
                    Logger.getLogger(ChatPane.class.getName()).log(Level.SEVERE, null, ex);
                }
于 2012-11-17T13:31:26.603 回答