- 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 display a bold text inside the JTextArea in Java?
A JTextArea class can extend JTextComponent and allow a user to enter multiple lines of text inside it. A JTextArea can generate a CaretListener interface, which can listen to caret update events. We can set a font to a text inside the JTextArea by using setFont() method.
Example
import java.awt.*; import javax.swing.*; public class JTextAreaTextBoldTest extends JFrame { private JTextArea textArea; public JTextAreaTextBoldTest() { setTitle("JTextAreaTextBold Test"); setLayout(new BorderLayout()); textArea= new JTextArea(); textArea.setLineWrap(true); textArea.setWrapStyleWord(true); Font boldFont=new Font(textArea.getFont().getName(), Font.BOLD, textArea.getFont().getSize()); textArea.setFont(boldFont); // bold text add(textArea); setSize(375, 250); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setLocationRelativeTo(null); setVisible(true); } public static void main(String[]args) { new JTextAreaTextBoldTest(); } }
Output
- Related Articles
- How can we display the line numbers inside a JTextArea in Java?
- How can we implement line wrap and word wrap text inside a JTextArea in Java?
- Java Program to display the contents in JTextArea
- How can I append text to JTextArea in Java?
- How to display JTextArea in the form of a table with GridLayout in Java?
- Java Program to paste clipboard text to JTextArea
- How to display "No records available" text in a JTable in Java? \n
- How to use Bold & Non-Bold Text In A Single UILabel in iOS/iPhone?
- How to make text bold in HTML?
- How to create a bold text using JavaScript?
- How to bold text in checkbox in Excel?
- How to display the different font items inside a JComboBox in Java?
- How to add bold annotated text in Matplotlib?
- How to make a text bold and italic in JavaFX?
- How to display a JRadioButtonMenuItem in Java?\n

Advertisements