0

I'm working with the Window Builder plugin for Eclipse.

When I execute the below code it shows the JDialog correctly. I was expecting the JDialog to show in the design tab (at design time) as well, but it won't.

package testshowjdialog;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.SwingUtilities;

public class MyJDialog extends JDialog {

    private static final long serialVersionUID = 1L;

    public MyJDialog(JFrame parent) {
        super(parent, true);


        setTitle("A Title");

        JButton button = new JButton("Test");
        add(button);

        setSize(100, 100);
    }

    /**
     * @wbp.parser.entryPoint
     */
    public static void main(String [] args) {
        SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
                MyJDialog dialog = new MyJDialog(new JFrame());
                dialog.setVisible(true);
            }
        });
    }
}

Any idea why?

Piovezan
  • 3,215
  • 1
  • 28
  • 45
  • what means "it won't"? Is there an error message? Try removing the comment above the main-method specifying the entryPoint for the windowbuilder. I'm not sure windowbuilder can parse that main-method and it might be better off just parsing the constructor. – cello Jul 05 '19 at 18:19
  • @cello Hello, "it won't" means "it won't show". No error message appears, just an empty JFrame. Just to let you know, I got the idea of the JavaDoc from here: https://stackoverflow.com/questions/56877262/unable-to-apply-composition-over-inheritance-in-java-swing. Removing the JavaDoc or even the main-method altogether worked! If you write an answer I'll gladly accept it. Thanks! – Piovezan Jul 05 '19 at 18:31
  • Your code works fine as is on my Windows 10 machine with Eclipse 2019-06 and JDK 12.0.1 and WindowBuilder 1.10.0.201812270937 – Abra Jul 05 '19 at 19:01
  • @Abra Thanks for the information. Just to be sure, the issue happens when the design tab is opened, is that what you are doing to check it works? The code compiles and runs fine even in my install. – Piovezan Jul 08 '19 at 13:06
  • Of course I opened the class in the design tab. – Abra Jul 08 '19 at 15:52

1 Answers1

1

Try removing the comment above the main-method specifying the entryPoint for the WindowBuilder.

This comment is usually used when a window/dialog is created not as its own class, but in a method of another class. Think of a method showCustomDialog() that creates and shows the dialog, but the class does lots of other stuff in other methods. Then, one can tell WindowBuilder where it should start parsing the code to detect which window/dialog it should show for editing.

Most likely, WindowBuilder is not able to correctly parse your main-method and does not recognize what window/dialog you try to create, and thus only shows an empty frame. Removing the entrypoint-comment will WindowBuilder make parse the Constructor of your class, which should work out better.

cello
  • 5,356
  • 3
  • 23
  • 28