All swing components
Java Swing is a graphical user interface (GUI) toolkit that is part of the JFC (Java Foundation Class) and helps design window-based applications. Java Swing is a compact and platform-independent framework that includes a variety of elements and container classes.
Also, the Java swing library is constructed on top of the AWT (Abstract Windows Toolkit), an API. Users might find an effective and easy-to-use interface in each application, giving them the flexibility to use the app.
Swing components are the fundamental components of an application. Swing is a Java GUI component toolkit. Every program has a primary dynamic user interface - a button, check-box, radio button, text field, etc. Swing is made up of these parts.
JButton
To construct a push button on the UI, we apply the JButton class. The button may contain display text or graphics. When selected and double-clicked, it produces an event. We may implement a JButton in the program by invoking any of its constructors.
Syntax:
JButton obj = new JButton(“Click”);
JLabel
The JLabel class object provides a component for inserting text into a container. It is used to show a single line only available for reading text. A program can update the text, but users cannot modify it directly. It is a branch of the JComponent class.
Syntax:
JLabel textLa = new JLabel(“This indicates the 1st L…”);
JLabel has four constructors. These are called:
JLabel() JLabel(String st) JLabel(Icon in) JLabel(String st, Icon in, int horiAlign)
JTextField
The JTextField creates a single-line text that is an editable box. Non-formatted text can be entered into the box by users. By using its constructor and giving an optional integer parameter, we may give the initial value to the text field.
This option specifies the box width as a function of the number of columns. It also does not restrict the number of characters entered into the box.
Syntax:
JTextField textbook = new JTextField(50);
It is the most extensively used text component. It has three designers:
JTextField (int col) JTextField(String st, int col) JTextField (String str)
Note: col denotes the total number of columns in the field's contents.
JCheckBox
To construct a JCheckBox, use the JCheckBox class. It enables (true) or turns off (false) an option. When you click on a CheckBox, its status changes from "on" to "off" or from "off" to “on."It derives from the JToggleButton class.
Syntax:
CheckBox ckBox = new JCheckBox(“Java Swings Concept”, true);
It provides a checkbox labeled "Java Swings Concept.”Make a note of the constructor's second argument. It is a boolean value that represents the checkbox's default state. True indicates that the checkbox is set to the "on" position by default.
JRadioButton
To make a radio button, use the JRadioButton class. It is used to select one of several options. It is frequently used in examination systems or quizzes.
It must be added to ButtonGroup to allow only a single radio button to be selected.
Syntax:
JRadioButton jradiob= new JRadioButton("Easys");
JComboBox
JComboBox belongs to the Java Swing component. JComboBox serves as an of JComponent. JComboBox presents a pop-up window with a selection of options that the user can select. JComboBox may be editable or read-only, according to the programmers like.
Syntax:
JComboBox jcomb = new JComboBox(id);
JTextArea
JTextArea is a class in Java that illustrates a multiline display of a text-containing area. It additionally serves as a tool for editing text and extends the class of Java's swing components.
The font size and color of the text added with the new text setting can be changed. All of these text spaces may be modified based on the requirements and preferences of the user. Together with java.awt.TextArea class, source compatibility, and map compatibility may be easily implemented.
Syntax:
JTextArea text_area=new JTextArea(“Coding improves skills");
The JTextArea has four constructors:
JTextArea() JTextArea (String st) JTextArea (int rows, int columns) JTextArea(String Sts, integer row, integer column)
JPasswordField
JPasswordField is a small component that allows you to change only one line of text without identifying the original contents, even if the view indicates that anything was written.
JPasswordField has been considered source-compatible within java.awt.TextField operates with an echoChar set. A TextField with echoChar set is used.
It is provided independently to make changing the JTextField's interface easier and safer without impacting password inputs.
Syntax:
JPasswordField pass = new JPasswordField();