I want a jButton to replace a selected text with the new text in a
JTextPane. How can i do that?
JTextPane p = new JTextPane;
JButton b = new JButton("Replace Text");
assume the user has selected a text... now what do i do?
b.setActionCommand( ? );
Where is a reference for all setActionCommand arguments? or can i pass
a function instead of a string?
b.setActionCommand( p.replaceSelection("New Text") ) ?
obviously, this will not work...
any hints?
Roland - 30 Apr 2005 23:59 GMT
> I want a jButton to replace a selected text with the new text in a
> JTextPane. How can i do that?
[quoted text clipped - 14 lines]
>
> any hints?
There are more ways to implement this. I usually use something like the
following:
final JTextPane p = new JTextPane();
JButton b = new JButton("Replace Text");
b.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
p.replaceSelection("New Text");
}
});

Signature
Regards,
Roland de Ruiter
___ ___
/__/ w_/ /__/
/ \ /_/ / \