Hello everyone, Java Swing is probably no longer a stranger to Java programmers, right? Although there are not many applications that use this technology anymore, in teaching it is still one of the content that is taught a lot at universities.
The reason is because this technology is very accessible, allowing Java learners to create Desktop applications more quickly and simply.
Usually, we will use software like Netbean or IntelliJ Idea, These are all very good support tools for this. But many Java programmers are used to using Eclipse, but unfortunately Eclipse does not directly support Java Swing by default.
So how can you use Eclipse to code Java Swing (drag and drop)? Well, in this article I will show you how Install WindowBuilder plugin on Eclipse for Java Swing programming on Eclipse an easier way.
Instructions for installing WindowBuilder on Eclipse
+ Step 1: After installing Eclipse, now to install any plugin on Eclipse, you can go to:
Eclipse Marketplace… as shown below.
+ Step 2: A dialog box as shown below appears, you search for your keywords
window builder => and select the result as shown in the picture then press
Install (here because I have installed it before, so the picture below is Uninstall).
+ Step 3: The next step will be to confirm the components and functions that will be installed. Here I choose all (because it’s not too heavy and also to avoid errors when installing)
=> Then you press
Confirm to confirm the selected components.
After confirming, press
Finish to start installing these components.
+ Step 4: After installing the plugin, Eclipse will ask to Restart the application to activate the plugin we just installed, then click
+ Step 5: Okay, that’s the plugin installation step. Now we will create a simple Java Swing project with Eclipse. First you create a new project:
Creating a Java project in Eclipse is quite simple, you just need to name the project, the options about the JRE you leave the default as shown below and then click
Finish is to be.
After creating a project (project), you choose:
Other.. (or the shortcut is
Ctrl + N) to create a new JFrame.
Scroll down and you will see the folder
WindowBuilder. Here you choose
Jframe => then press
JFrame It’s also very simple, you just need to give it a name and then press
Well, after creating a JFrame, below is our source code. In fact, when programming Java Swing, you will rarely have to write code, but mainly drag and drop the interface (unless your application has function buttons that must use code).
Now, you switch tabs
Design by clicking on the tab
Design as shown below.
This process may take a while for Eclipse to load the interface (for the first time after creating the Project).
And below is the opening interface when you use Eclipse to program JavaSwing. (You guys who use Netbean are probably too familiar with this interface space, right :D)
Of course, the interface on Eclipse will be a bit different from other tools and also depending on which tool you are using, you will feel there are advantages and disadvantages.
Now I will try to create an interface that displays the word BLOG SHARE KNOWLEDGE.
I will “drag” into interface one
JLabel (other components you also drag and drop similarly) => then I adjusted the font size, font and center for the text.
Finally, to preview the result, right-click on the frame => and select
Test/Preview… is to be.
Okay, this is our result, of course, this is just an example so I made it pretty simple. You can completely drag and drop and create more complex and quality applications.
So with just a few very simple steps, programmers who are in the habit of working with Eclipse can JavaSwing programming right on Eclipse instead of having to switch to other tools like Netbean or IntelliJ Idea.
Hope this article will be useful to you. See you in the next posts!
CTV: Nguyen Duc Canh – Blogchiasekienthuc.com
Note: Was this article helpful to you? Don’t forget to rate the article, like and share it with your friends and family!