Header Ads Widget

Responsive Advertisement

Ticker

6/recent/ticker-posts

Set JTextArea text bold (Java)

Source code below will show you, how to set JTextArea text to bold.

***************************************************************************
COMPLETE SOURCE CODE FOR : SetJTextAreaTextBold.java
***************************************************************************
import javax.swing.JTextArea;
import javax.swing.JFrame;

import java.awt.BorderLayout;
import java.awt.Font;

public class SetJTextAreaTextBold
{
public static void main(String[]args)
{
 //Create text area using JTextArea
 JTextArea textArea=new JTextArea();

 //Set line wrap to true
 textArea.setLineWrap(true);

 //Create font.
 //Font Name : Default text area font
 //Font Style : Bold
 //Font Size : Default text area font size
 Font newTextAreaFont=new Font(textArea.getFont().getName(),Font.BOLD,textArea.getFont().getSize());

 //Set JTextArea font using new created font
 textArea.setFont(newTextAreaFont);

 //Create a window using JFrame with title ( Set JTextArea text bold )
 JFrame frame=new JFrame("Set JTextArea text bold");

 //Set JFrame layout to BorderLayout
 frame.setLayout(new BorderLayout());

 //Add created text area into JFrame
 frame.add(textArea);

 //Set default close operation for JFrame
 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

 //Set JFrame size
 frame.setSize(400,500);

 //Make JFrame visible
 frame.setVisible(true);
}
}


***************************************************************************
JUST COMPILE AND EXECUTE IT
***************************************************************************