- 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
Advertisements