SwaMPlaC0re SwaMPlaC0re - 4 months ago 9
Java Question

WindowBuilder: absolutely no effect on the GUI

I'm using Eclipse 3.7.2 and I would like to use WindowBuilder too. My problem is it generates useless code for me. When I'm running my application I can see nothing but a little piece of the titlebar of the window of my program. This window's size is 0×0 no matter what have I set through the code. When I'm resizing it there is just a blank frame and nothing else. It turned out when I was debugging my code that the constructor - made by WindowBuilder - has been called and running without errors. However this constructor does not make any effect on my program. I have no clue what to do.

thanks

Answer

When you go "New" > "Other" > "WindowBuilder" > "Swing designer" > "JFrame" (than name your class) you should get this:

import java.awt.BorderLayout;
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;

public class Stack extends JFrame {

private JPanel contentPane;

/**
 * Launch the application.
 */
public static void main(String[] args) {
    EventQueue.invokeLater(new Runnable() {
        public void run() {
            try {
                Stack frame = new Stack();
                frame.setVisible(true);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });
}

/**
 * Create the frame.
 */
public Stack() {
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setBounds(100, 100, 450, 300);
    contentPane = new JPanel();
    contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
    contentPane.setLayout(new BorderLayout(0, 0));
    setContentPane(contentPane);
}

}

In oposite way: Go "Help" > "Install new software" > " already installed". Check that you have installed these things (Swing designer and below):

enter image description here