Set JTextArea text bold and italic

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

**********************************************************************
COMPLETE SOURCE CODE FOR : SetJTextAreaTextBoldAndItalic.java
**********************************************************************


import javax.swing.JTextArea;
import javax.swing.JFrame;

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

public class SetJTextAreaTextBoldAndItalic
{
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 And Italic
//Font Size : Default text area font size
Font newTextAreaFont=new Font(textArea.getFont().getName(),Font.ITALIC+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 and italic )
JFrame frame=new JFrame("Set JTextArea text bold and italic");

//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
**********************************************************************

RELAXING NATURE VIDEO