0

I have two Jtextpane what i want to do is that i what to select the text from 1 Jtextpane and i want that it should appear in the second Jtextpane after a menu item Edit is selected

which i have done

 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;

                        }
                    }
                });

Now I am clueless that how would i put the edited text back to the selcted position from where i got the text can anyone tell the solution

Complicated
  • 117
  • 2
  • 16

1 Answers1

0

Thank you

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);
                }
Complicated
  • 117
  • 2
  • 16
  • now what i want is how to change the background color of the selected text area – Complicated Nov 17 '12 at 13:32
  • Post another question instead of comments on your own answer. Take a look at [this question](http://stackoverflow.com/questions/13074428/how-can-i-set-each-character-to-a-different-color-background-color-in-a-jtextpan/13077749#13077749) and [this one](http://stackoverflow.com/questions/13285526/jtextpane-text-background-color-does-not-work) – Guillaume Polet Nov 17 '12 at 15:02