Swing

JCheckBox JRadioButton Example Java Swing

JCheckBox JRadioButton: The Swing GUI components contain three types of state button s— JToggleButton, JCheckBox and JRadioButton — that have on/off (or true/false) values. JToggleButtons are frequently used with toolbars (sets of small buttons typically located on a bar across the top of a window). Classes JCheckBox and JRadioButton are subclasses of JToggleButton. Following is …

JCheckBox JRadioButton Example Java Swing Read More »

JTextField Login Validation Example Java Swing

In the following program, user name and password are taken from user using JTextField and JPasswordField. import javax.swing.*; // for JTextField, JPasswordField, ImageIcon etc. import java.awt.*; // for Container class import java.awt.event.* ; // ActionEvent, ActionListener public class TextAndPassValidation extends JFrame implements ActionListener { JTextField tf1, tf2; JPasswordField pf ; public TextAndPassValidation( ) { super(“Learning …

JTextField Login Validation Example Java Swing Read More »

JLabel Example Multiline Text Java Swing

One of the important features of JLabel is it can be displayed as multiple lines of text with bullets, a very contrast of AWT Label which gives only one line of text. We use HTML here. Following code on JLabel Example explains. import javax.swing.* ; import java.awt.*; import java.awt.event.*; public class JLabelDemo3 extends JFrame { …

JLabel Example Multiline Text Java Swing Read More »

JLabel Border and Image Example

Swing Label can be set with borders and images which is not possible with AWT Label component. Alignment is also possible. Following code explains. import javax.swing.* ; import java.awt.*; import java.awt.event.*; public class JLabelDemo2 extends JFrame { public JLabelDemo2() { Container c = getContentPane(); c.setLayout(new GridLayout(3, 1, 0, 10)); // ordinary text like Label of …

JLabel Border and Image Example Read More »

JOptionPane Display Message Swing Example

JOptionPaneSwing is used to display message to the user in a window (separate dialog box). It is the easiest way of displaying message in swing. This can be used in non-gui programs also. Example on JOptionPane using showMessageDialog() method import javax.swing.*; public class JOptionPaneDemo { public static void main(String args[]) { String str = “SN …

JOptionPane Display Message Swing Example Read More »

JButton Border Example

JButton Border Example Note: It is advised to read Java JFC Swing Introduction and Swing Overview before reading this. In the following program on JButton Border Example, special features like mnemonic(shortcut key), setting borders and images are discussed. import javax.swing.*; import java.awt.*; import java.awt.event.* ; public class JButtonDemo3 extends JFrame implements ActionListener { JButton rb, …

JButton Border Example Read More »