JSwing simple login form

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.

JSwingApplication tree view

 

Create a JSwing form

  1. Open Apache NetBeans.
  2. 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.
  3. In the Name and Location window, enter Login in the Class Name, change Location to Source Packages, package to form, and then click Finish.
Create a JSwing Form

 

Drag components onto the form

  1. 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.
  2. Repeat step 1, and add three JLabels, two JTextFields, and three JButtons to the form, shown in the following.
Add Components

 

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.

ComponentstextactionCommandname
jLbael1UserName username
jLbael2Password password
jLbael3Message message
jButton1Loginloginlogin
jButton2Resetresetreset
jButton3Cancelcancelcancel
jTextField1  user_text
jTextField2  pwd_text

  1. Click jLabel1, in the Properties, change the text to UserName, change the name to username
  2. Repeat step 1 for the rest of the components, shown in the following.
Change Properties

 

Preview the form

Click Preview Design for a preview

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).

Share this page

Let more people know about this site, please share