IntelliJ is suggesting that I change
new AbstractAction() {
public void actionPerformed(ActionEvent e) {
// my code here
}
}
to
(AbstractAction) (e) -> {
// my code here
}
When I change my code to the suggested code above, I get the message "target type of a lambda conversion must be an interface".
You should implement abstract action class, so you can use it functionally.
public class FunctionalAction extends AbstractAction {
ActionListener myaction;
public FunctionalAction(ActionListener customaction) {
this.myaction = customaction;
}
@Override
public void actionPerformed(ActionEvent e) {
myaction.actionPerformed(e);
}
public ActionListener getMyaction() {
return myaction;
}
public void setMyaction(ActionListener myaction) {
this.myaction = myaction;
}
}
You can use this class as below:
getTexfield().getActionMap().put(actionName, new FunctionalAction(ae -> {
}));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With