Listener creation not inline

已回答

Hello,

is there a way to set up the action listener method creation as not inline? Means, currently as I generate a new action listener, IDEA creates a new nested function inside the constructor, such as:

public MainForm() {
cmp_btn_open.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {

}
});
}

But is there a way to create the following code instead:

public MainForm() 
{
cmp_btn_open.addActionListener(e -> actionPerformed_cmp_btn_open(e));
}

public void actionPerformed_cmp_btn_open(ActionEvent e)
{

}

For me this makes more sense because I can reuse the created function. Further, it is better to understand. Is there such a way for the auto-generated listeners of any kind?

Best regards,
Jib.

0

Hello,

Please clarify, by "generation" you mean the completion of the anonymous class when you type new ActionListener? Thanks

0
Avatar
Permanently deleted user

Hey Olga Klisho,

no, what I meant was the auto-generation through the GUI Designer. I can select my component in the GUI Designer with right-click and select "Create Listener". If I do create an action listener for buttons, for example, I get an inline function like as mentioned in my first post. Is there actually a way to generate action listener functions like mentioned in my first post?

Best regards, Jib.

0

Hello,

I've created an issue at the YouTrack so that your question can be discussed directly with developers, please follow:

https://youtrack.jetbrains.com/issue/IDEA-240110

1
Avatar
Permanently deleted user

Thank you, Olga! I gonna watch there.

0

请先登录再写评论。