Basic
Controls
Layout
Java swing consists of components or widgets to develop Graphical User Interface Applications. Java swing is a part of JFC (Java Foundation Class). JFC consists of AWT, swing, and java2D. There are two types of widget toolkits Light Weight and Heavy Weight. Java Swing is Lightweight GUI Toolkit that includes Buttons, Textboxes, etc...…
Java Swing components are platform-independent. Swing is a pluggable look and feels swing that follows the MVC framework. In Java Swing Container class plays an important role. The container class holds all the widgets. A container class is divided into three type's panels, Frame, and Dialog.
To develop a java GUI application, Java Swing and AWT support two technologies. Compared with java, AWT swing is richer in terms of components. Swings provide additional functionalities and added components to replace AWT. A most important feature of the swing is its components are platform-independent. Java swing uses the MVC framework. Thus, it provides a more flexible UI. Swing components are lightweight components. Java swings are built-in double buffering. Swing components are different looks and feel.
Java swing is used to develop desktop applications like billing or inventory applications and real-time applications to manage and control mechanical devices. Swings are also used to develop mobile applications like gaming, calculators, etc.…
It also supports developing a network-based application to manage clients in the network. These are very few examples of java swing uses since it's platform-independent. These benefits develop applications that run on any platform.
Simple java swing program to create a form for Student Registration.
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
public class StudentRegistration
{
public static void main(String[] args) {
Frame frame = new JFrame("Student Registration");
frame.setSize(350, 200);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel panel = new JPanel();
frame.add(panel);
placeComponents(panel);
frame.setVisible(true);
}
private static void placeComponents(JPanel panel)
{
panel.setLayout(null);
JLabel userLabel1 = new JLabel("First Name");
userLabel1.setBounds(10,20,80,25);
panel.add(userLabel1);
JLabel userLabel2 = new JLabel("Last Name");
userLabel2.setBounds(10,50,100,25);
panel.add(userLabel2);
JLabel userLabel3 = new JLabel("Email ID");
userLabel3.setBounds(10,80,80,25);
panel.add(userLabel3);
JLabel userLabel4 = new JLabel("Phone No.");
userLabel4.setBounds(10,110,80,25);
panel.add(userLabel4);
JTextField fname = new JTextField(20);
fname.setBounds(100,50,165,25);
panel.add(fname);
JTextField lName = new JTextField(20);
lName.setBounds(100,20,165,25);
panel.add(lName);
JTextField email = new JTextField(20);
email.setBounds(100,80,165,25);
panel.add(email);
JTextField phNO = new JTextField(20);
phNO.setBounds(100,110,165,25);
panel.add(phNO);
JButton loginButton = new JButton("Register");
loginButton.setBounds(10, 160, 80, 25);
panel.add(loginButton);
JButton clearButton = new JButton("clear");
clearButton.setBounds(100, 160, 80, 25);
panel.add(clearButton);
}
}
Output:
Some basic knowledge about java programming and listening is a must while working with java swing. A Java event listener of AWT components and packages is necessary to some extent. Basic knowledge regarding form designing and alignment is also required. Netbeans IDE is well suited to developing desktop GUI applications targeting swings.
The target audience includes soft professionals and beginners who are willing to learn java swings. Since it's easier to design GUI applications compared to AWT for beginners who are eager to learn from design or desktop applications, swings are the easiest way.
By signing up, you agree to our Terms of Use and Privacy Policy.
By signing up, you agree to our Terms of Use and Privacy Policy.
Valuation, Hadoop, Excel, Web Development & many more.
This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy