3

I found this code on the internet. I am setting up a new Eclipse on my new laptop and I want to be able to open this in design view.

How do you open a class with JComponents' on it in design view and also is there a way to make that the default?

Seems like and easy thing but I have been looking for this in Eclipse for the better part of an our. I thought it was in Open With... but I didn't see anything that that sounded like design view.

I hope this is a good question because I just cannot simple find the design view button.

code:

package TestMenu;

import javax.swing.JFrame;
import javax.swing.JLabel;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.SwingUtilities;

public class StartupWindow extends JFrame implements ActionListener
{
    private static final long serialVersionUID = 1L;
    private JButton btn;

    public StartupWindow()
    {
        super("Simple GUI");
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        btn = new JButton("Open the other JFrame!");
        btn.addActionListener(this);
        btn.setActionCommand("Open");
        add(btn);
        pack();

    }

    @Override
    public void actionPerformed(ActionEvent e)
    {
        String cmd = e.getActionCommand();

        if(cmd.equals("Open"))
        {
            dispose();
            new AnotherJFrame();
        }
    }

    public static void main(String[] args)
    {
        SwingUtilities.invokeLater(new Runnable(){

            @Override
            public void run()
            {
                new StartupWindow().setVisible(true);
            }

        });
    }
}

class AnotherJFrame extends JFrame
{
    private static final long serialVersionUID = 1L;

    public AnotherJFrame()
    {
        super("Another GUI");
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        add(new JLabel("Empty JFrame"));
        pack();
        setVisible(true);
    }
}
Doug Hauf
  • 3,025
  • 8
  • 46
  • 70

6 Answers6

14

If by "design view" you mean the Eclipse Windowbuilder, you can open that with "Open with ..." > "WindowBuilder Editor." However, I have tested your code with a Kepler SR1 Eclipse on Mac OS X, and got the following error message in the Design View, which I guess means that you won't be able to use it in the Design View as is.

The parser parsed the compilation unit, but can't identify any GUI toolkit, so WindowBuilder can't display any GUI to edit.

In your case I'd try to create a new WindowBuilder class from the wizard, and re-create the class from scratch, e.g., in the Design View.

In case you cannot find the option WindowBuilder Editor in the Open with ... menu at all, perhaps you'll need to install WindowBuilder in your new Eclipse instance first. To do this, go to https://www.eclipse.org/windowbuilder/download.php, pick the link to the release version update site for your version of Eclipse (the one for Kepler SR1 is http://download.eclipse.org/windowbuilder/WB/release/R201309271200/4.3/), and install via "Install New Software" (or follow the instructions from the update site link, which includes comprehensive installation details).

s.d
  • 4,017
  • 5
  • 35
  • 65
3

In Eclipse go to Menu/Help/Install New Software. Put link you want to install there and(enter if it's not refresh)

enter image description here

You can get link here: https://www.eclipse.org/windowbuilder/

bravohex
  • 966
  • 13
  • 21
2

This may be too late but I also had a hard time looking for the design tab on the internet. It's not stated on the links I've went to. Basically, head over to the tab that you created with WindowBuilder with the code and look at the bottom of your screen. I have a picture just so everyone can have a reference of it.

Depending on your perspective or how you setup your tabs, it should be right under the text editor. Depending on your perspective or how you setup your tabs, it should be right under the text editor.

CraftedGaming
  • 499
  • 7
  • 21
2

Right click on the class -> Open With -> WindowBuilder Editor

https://www.eclipse.org/forums/index.php/t/237691/

0

if you have Windows Builder added to eclipse: Right click on the java file, select open with > WindowBuilder Editor

at bottom of file there is one option named as Design click on that.

enter image description here

Ritesh Kumar
  • 129
  • 1
  • 7
0

Just like others said, the solution is to right-click on the file and choose Open with ... > WindowBuilder Editor. Then the Design panel should appear on the bottom left of your screen.

There might be two exceptional cases:

  1. The WindowBuilder Editor might not be installed, then you can click on Help > Install New Software.... Finding the WindowBuilder Editor should not be a problem.
  2. The WindowBuilder Editor might be outdated if, for example, the eclipse version is modified. You can then click on Help > Eclipse Marketplace..., and then type for the latest stable version of WindowBuilder Editor.

Conclusion: If problems with the Design panel arose, it might be a good solution to check the WindowBuilder Editor as well.

hokwanhung
  • 305
  • 2
  • 10