- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Java Program to change JLabel text after creation
At first, set a text for JLabel −
JLabel label; label = new JLabel("First Label");
Now change the above JLabel text using setText() −
// changing text label.setText("Updated text");
Example
import java.awt.Font; import javax.swing.*; public class SwingDemo { public static void main(String args[]) { JFrame frame = new JFrame("Label Example"); JLabel label; label = new JLabel("First Label"); label.setBounds(50, 50, 100, 30); label.setFont(new Font("Verdana", Font.PLAIN, 13)); // changing text label.setText("Updated text"); frame.add(label); frame.setSize(500,300); frame.setLayout(null); frame.setVisible(true); } }
Output
- Related Articles
- How to change text font for JLabel with HTML in Java?
- Java Program to set alignment for text in JLabel
- How to change JLabel font in Java
- How to change JLabel size in Java?
- How to change index values of a Pandas series after creation?
- How to align JLabel text vertically top in Java?
- How to change JLabel background and foreground color in Java?
- How can we rotate a JLabel text in Java?
- How to create JLabel to hold multiline of text using HTML in Java?
- How can we implement a moving text using a JLabel in Java?
- Java Program to center a JLabel in a JPanel with LayoutManager
- How to send message from firebase console after creation project?
- Changing Matplotlib subplot size/position after axes creation
- How to set the text of the JLabel to be right-justified and vertically centered in Java?
- Creation of .ASM file using a text editor

Advertisements