Create an application named about the system

In various desktop applications, we can always see information about the system version or copyright notice, and it has HTML content that can link to the website of the system. In this tutorial, we will create an application named about the system to show you how to use HTML content in JLabels.

You will learn how to:

  • Change the background image of JLabel.
  • Put html tags in a JLabel.

 

Prerequisites

Before you start reading this tutorial, you must:

  1. Familiar with Java swing development, go oracle Java Swing to get tutorials reference.
  2. Have read the previous three tutorials on JSwing.
  3. Familiar with the Operation of Apache NetBeans.

 

Create an About Form

  1. Create a JFrame called About on packages form, and then add components to the JFrame, tree diagram as shown below.

    About tree view

  2. Change the JLabel1's icon.

    About JLabel icon

  3. Change the JLabel2 text with the below.
    <html>&ensp;NetBeans IDE and NetBeans Platform are based on Apache NetBeans from<br>
    &ensp;the Apache Software Foundation and are licensed under <a href="https://www.apache.org/licenses/LICENSE-2.0">Apache License<br>
    &ensp;Version 2.0</a>. For more information, please visit <a href="https://netbeans.apache.org/">netbeans.apache.org.</a></html>
  4. Change the JLabel3 text with the below.
    <html> <strong>&ensp;Product Version:</strong> Apache NetBeans IDE 13<br> <strong>&ensp;Java: 18.0.1.1</strong>; Java HotSpot(TM) 64-Bit Server VM 18.0.1.1+2-6<br> <strong>&ensp;Runtime</strong>: Java(TM) SE Runtime Environment 18.0.1.1+2-6<br> <strong>&ensp;System</strong>: Windows 7 version 6.1 running on amd64; UTF-8; zh_TW (nb)<br> <strong>&ensp;User directory</strong>: C:\Users\hsichi.jam.DC\AppData\Roaming\NetBeans\13<br> <strong>&ensp;Cache directory</strong>: C:\Users\hsichi.jam.DC\AppData\Local\NetBeans\Cache\13</html>
  5. Change JButton properties of text, actionCommand and name value to Close, shown as the following.

    About Form

Create an About App

Create a Java class named About on the packages app, and then add the following code to the Class.

package app;
import jswing.application.*;

public final class About extends App {

    public static void main(String args[]) {

        javax.swing.SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
                Form.open("form.About","About");
                UserInterface.initialize("app.About",Form.getCurrentForm());
            }
        });
    }
    
    @Override
    public void actionPerformed(java.awt.event.ActionEvent e){
        String action = e.getActionCommand();
        switch(action){
            case "Close":
                System.exit(0);
                break;
        }
    }
}

 

Run application

Press Shift+F6 to run.

About

 

Practice

After this tutorial, you will find a problem with JLabel in which hyperlinks can not be opened, think about how to solve it.

Tips

  1. The hyperlinkUpdate may be useful.

 

Next steps

Congratulations! You've completed the About page using JSwing. You can easily migrate to your application. Click download source code or next for more tutorials.

Share this page

Let more people know about this site, please share