- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
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
How to disable a JLabel in Java?
To disable a JLabel, use the setEnabled() method −
JLabel label; label.setEnabled(false);
The following is an example to disable a JLabel −
package my; import java.awt.Color; import java.awt.Dimension; import java.awt.Font; import javax.swing.*; import javax.swing.border.Border; public class SwingDemo { public static void main(String args[]) { JFrame frame = new JFrame("Demo"); JLabel label; label = new JLabel("First Label",JLabel.RIGHT); label.setVerticalAlignment(JLabel.TOP); label.setFont(new Font("Verdana", Font.PLAIN, 15)); label.setPreferredSize(new Dimension(250, 100)); label.setForeground(new Color(120, 90, 40)); label.setBackground(new Color(100, 20, 70)); label.setEnabled(false); Border border = BorderFactory.createLineBorder(Color.ORANGE); label.setBorder(border); frame.add(label); frame.setSize(600,300); frame.setVisible(true); } }
Output
- Related Articles
- How to change JLabel font in Java
- How to change JLabel size in Java?
- How to add tooltip to JLabel in Java?
- How to disable a MenuItem in Java?
- How to add line border to JLabel in Java?
- How to center a JLabel in a JPanel with GridBagLayout in Java?
- How to create a JLabel with an image icon in Java?
- How to set location of JLabel in a JFrame with Java?
- How can we rotate a JLabel text in Java?
- How to align JLabel text vertically top in Java?
- How to change JLabel background and foreground color in Java?
- How to disable close button on a JFrame in Java?
- How to disable auto resizing for a JTable in Java?
- Java Program to center a JLabel in a JPanel with LayoutManager
- How to disable a Tab in a JTabbedPane Container with Java?

Advertisements