Important Notice: Our web hosting provider recently started charging us for additional visits, which was unexpected. In response, we're seeking donations. Depending on the situation, we may explore different monetization options for our Community and Expert Contributors. It's crucial to provide more returns for their expertise and offer more Expert Validated Answers or AI Validated Answers. Learn more about our hosting issue here.

Why does WindowBuilder generate widgets in the constructor?

0
Posted

Why does WindowBuilder generate widgets in the constructor?

0

WindowBuilder can generate code into any method that you like. One of the key features of WindowBuilder is its refactoring friendliness. You can actually use any template that you want for creating a new window (e.g., you don’t need to use the wizards supplied with WindowBuilder). Alternatively, you can use the Eclipse refactoring commands to extract the components into a new method (like createComponents()) and the tool will continue to work. Try the following template for example: import javax.swing.JFrame; public class MyFrame extends JFrame { public static void main(String args[]) { try { MyFrame frame = new MyFrame(); frame.setVisible(true); } catch (Exception e) { e.printStackTrace(); } } public MyFrame() { super(); createComponents(); } private void createComponents() { setBounds(100, 100, 400, 300); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } } If you start adding new widgets, they will be added to the createComponents() method.

Related Questions

What is your question?

*Sadly, we had to bring back ads too. Hopefully more targeted.