i started netbeans plugin development with this basic tutorial . and i modyfied it to get the text of current edited file.
so i created a action class which extends ActionListener .so when i click the icon of my plugin from toolbar it open dialog and show content.but it repeats .when i close another one open then another dialog so on..
i think this is because i add property each time listener when i click the button .so how can i fix this ..
this is the code i used
public final class SomeAction implements ActionListener {
@Override
public void actionPerformed(ActionEvent e) {
PropertyChangeListener l = new PropertyChangeListener() {
@Override
public void propertyChange(PropertyChangeEvent evt) {
JTextComponent jtc = EditorRegistry.lastFocusedComponent();
if (jtc != null) {
Document d = jtc.getDocument();
int msgType = NotifyDescriptor.INFORMATION_MESSAGE;
NotifyDescriptor df;
try {
df = new NotifyDescriptor.Message(d.getText(0, d.getLength() - 1), msgType);
DialogDisplayer.getDefault().notify(df);
} catch (BadLocationException ex) {
Exceptions.printStackTrace(ex);
}
}
}
};
EditorRegistry.addPropertyChangeListener(l); // i guess here is the problem but i couldn't able to find where should i put this line
}
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire