In the previous quick start, we explained that a JSwing application consists of a Form and an App, In this tutorial, we'll create a login form and explain how to set controls name and attributes value in the login form and its uses.
The form of JSwing applications is essentially java swing forms. You can write code or choose a form editor to build Forms. No matter which way you choose to create a form, we recommend that you use Apache NetBeans for the best learning experience. The Apache NetBeans provides the tools you need to create a form, to learn more, see Welcome to Apache NetBeans.
In this tutorial, we'll create a login form, and you will learn how to:
- Create a JSwing Form in NetBeans
- Add Java Swing Controls to the Form
- Change control names
- Set actionCommand for JButton
- Preview JSwing Forms
- Compile JSwing Forms
Prerequisites
This tutorial builds on the previous tutorial, Quick start guide, and we think you have created a JSwing project, as shown in the screenshot. If you haven't done that tutorial, go through that one first.
Create a JSwing form
- Open Apache NetBeans.
- Click JSwingApplication, Select File > New File, in the New File window, choose Swing GUI Forms in the Categories, select JFrame Form in the File Types, and then click Next.
- In the Name and Location window, enter Login in the Class Name, change Location to Source Packages, package to form, and then click Finish.
Drag components onto the form
- In the Palette, select the JPanel and then drag it onto the form, and adjust the position and size of the JPanel for the best display.
- Repeat step 1, and add three JLabels, two JTextFields, and three JButtons to the form, shown in the following.
Change property values
JSwing commonly uses the method getComponentByName, So we recommend that every component needs a unique name, Change property values via the following table.
Components | text | actionCommand | name |
---|---|---|---|
jLbael1 | UserName | username | |
jLbael2 | Password | password | |
jLbael3 | Message | message | |
jButton1 | Login | login | login |
jButton2 | Reset | reset | reset |
jButton3 | Cancel | cancel | cancel |
jTextField1 | user_text | ||
jTextField2 | pwd_text |
- Click jLabel1, in the Properties, change the text to UserName, change the name to username
- Repeat step 1 for the rest of the components, shown in the following.
Preview the form
Click Preview Design for a preview
Compile
It's necessary to compile the form file, If not, JSwing App can't open it, and then JSwing App is terminated.
Next steps
Advance to the next to learn how to add code to the JSwing application(App).