Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I create a new Swing app in IntelliJ IDEA Community edition?

Tags:

I have created a new project using the Create New Project Wizard, by choosing "create project from scratch" but it's completely empty (no java classes at all, so I manually created a new swing form inside the empty project).

In many other IDEs I have used there is a way to click once, and get a new "new Gui project", and I usually expect it in the "File -> New Project" wizard or something, comparable.

There is a new project wizard in the IntelliJ IDEA IDE, but it only seems it can create a blank project, and then I can manually add a form to it. So I did that. But then, that lacks any of the usual Java code that you would expect it to have, to open up that form and show it as an application.

I am trying to understand the features and capabilities of IntelliJ IDEA, and it seems strong as a very fast and efficient editor and debugger and build system GUI wrapper around the ANT build system, but I was wondering if there are more "RAD" features that I have merely overlooked. I have done a bit of googling and reading the docs, but I haven't found much about using IntelliJ IDEA to build a GUI application in Java.

Where I'm currently stuck is when I tried to build and run my empty project with an empty form in it, and I get to some kind of "Run" target configuration screen, and I tried clicking the [+] icon, and adding "MyForm01" which is the empty swing form I created, and it says in a dialog box "MyForm01 is not acceptable". I know enough java to know that the basic "GUI app skeleton code" is not being auto-generated by the IDE. I could go and copy and paste something from the internet, but my interest here is in knowing whether the tool can automatically be used to build a GUI, with a workflow as simple as other RAD-style GUI builder tools, including NetBeans, which is the java tool I am most comfortable using, or Delphi, which is my main everyday tool, which is Pascal based, rather than Java.

like image 266
Warren P Avatar asked Oct 08 '12 04:10

Warren P


People also ask

Does IntelliJ have swing?

GUI Designer in IntelliJ IDEA enables you to create graphical user interfaces (GUI) for your applications using Swing library components.


2 Answers

There is no such thing as GUI project in IDEA. You can add GUI forms there at any time you need, just by RightClick -> New -> GUI Form. You can create GUI app from it just by adding main() method into the form binding class. IDEA does the job for you if you hit Alt-Ins (or menu Code->Generate) when in the binding class editor. The only requirement for this is to place correct name for the form's root panel.

You also should check this manual to discover some other things: https://www.jetbrains.com/help/idea/designing-gui-major-steps.html. Anyway, the GUI builder is pretty intuitive.

like image 155
no id Avatar answered Sep 28 '22 05:09

no id


The following instruction applies to IntelliJ Idea 14.

  1. Enable UI Designer
    1. File → Settings → Plugins → UI Designer
  2. Enable generate Java class
    1. File → Settings → Editor → GUI Designer → change Generate GUI into “Java source code”
  3. Go to the project view, and right click the package name where you want the generated Java class to be stored
    1. On the context menu, choose New → GUI Form, and set the bound class
    2. In the designer, it will automatically put a Jpanel on the window. Choose Jpanel, and first set the Layout manager to GridLayoutManager(IntelliJ).
    3. Adding components as needed, make sure to give some value to “field name”. This value will become the name of this component in the form class.
    4. You can preview the form by right click and then choose preview.
    5. When you are done, change the layout manager for Jpanel to “GridBagLayout”.
  4. Click on Build → Make Project to generate Java source codes and store them in the bound Java class.
like image 23
chengl Avatar answered Sep 28 '22 05:09

chengl