This tutorial will show you How to Create JLabel With Text and add it to a JFrame . JLabel is a simple Graphical User Interface compo...
This tutorial will show you How to Create JLabel With Text and add it to a JFrame .JLabel is a simple Graphical User Interface component that is only used to show a text message.
Common JLabel Constructors
- JLabel(String s)-creates a JLabel with a text.
- JLabel(Icon icon)-creates a JLabel with ImageIcon.
- JLabel(Icon icon,String s)-creates a JLabel with both icon and text.
Create JLabel With Text Example Code.
[
import javax.swing.JLabel; import javax.swing.JTextField; import javax.swing.JPasswordField; import javax.swing.JFrame; public class JLabelExample extends JFrame{ public JLabel user,pass; public JPasswordField password; public JTextField username; JLabelExample() { super("JLabel Example"); user=new JLabel("Username"); pass=new JLabel("Password"); password=new JPasswordField(); username=new JTextField(); user.setBounds(10, 10, 200, 20); username.setBounds(100, 10, 200, 20); pass.setBounds(10, 50, 200, 20); password.setBounds(100,50 , 200, 20); add(user); add(username); add(pass); add(password); setLayout(null); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setSize(400,300); setVisible(true); } public static void main(String args[]) { new JLabelExample(); } }
]