Since, I get used to code in javascript, I want to create objects with properties.
Here is my code:
jPanel2.add( new JPanel(){ this.add(new JButton("Add")); });
Do you have any suggestions ?
Since, I get used to code in javascript, I want to create objects with properties.
Here is my code:
jPanel2.add( new JPanel(){ this.add(new JButton("Add")); });
Do you have any suggestions ?
You can always use this syntax:
container.add(new JPanel() {{ this.add(new JButton("Add")); }});
Full example:
public static void main(String[] args) throws Exception {
JFrame frame = new JFrame("Test");
frame.add(new JPanel() {{ this.add(new JButton("Add")); }});
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setVisible(true);
}