1

How can I create a custom JPanel with IntelliJ GUI designer? I created a new form and bound it to a custom class.

enter image description here

But TestingPanel is just a basic class.

public class TestingPanel {
    private JButton button1;
    public JPanel panel1;
    private JButton button2;
    private JButton button3;
}

now when I want to use JPanel I am forced to do something like this:

JPanel testingPanel = new TestingPanel().panel1;

I would expect that I can design my custom JPanel in GUI designer and than do advanced operations with it (adding listerners etc.) in code. Something like this:

public class TestingPanel extends JPanel {
    private JButton button1;
    private JButton button2;
    private JButton button3;

    public void onCreate() {
         //change name, add listeners etc.
    }

}

How can I do this? Thanks for any help.

tom1299
  • 75
  • 10
bezoadam
  • 587
  • 2
  • 8
  • 18
  • Probably you should read about [aggregation over inheritance](https://stackoverflow.com/questions/269496/inheritance-vs-aggregation) principle. – Sergiy Medvynskyy Nov 14 '18 at 07:45
  • I am familiar with these principles but I don't know how to achieve this in IntelliJ IDEA. – bezoadam Nov 14 '18 at 07:50
  • I would suggest you forget about the IDE and learn how to code this manually. This way you are learning Java/Swing and not the IDE. What happens if you ever need to change the IDE you will need to relearn the IDE. Just use the IDE to help in compiling and debugging. But don't depend on it to generate forms. – camickr Nov 14 '18 at 15:00

0 Answers0