While I'm not sure whether using the JOptionPane is the best option for the purpose, you can add a text area, or any other form component into an OptionPane. Since you have asked specifically for a TextArea, I have added a JTextField and a JTextArea in the following example.
import java.awt.Color;
import java.awt.Dimension;
import javax.swing.BorderFactory;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.SpringLayout;
public class Main {
public static void main(String[] args) {
JFrame frame = new JFrame("Option Pane Text Area Example");
final SpringLayout layout = new SpringLayout();
final JPanel panel = new JPanel(layout);
panel.setPreferredSize(new Dimension(250, 160));
JLabel lblName = new JLabel("Name");
panel.add(lblName);
JTextField txtName = new JTextField(10);
txtName.setBorder(BorderFactory.createLineBorder(Color.black));
panel.add(txtName);
JLabel lblAddress = new JLabel("Address");
panel.add(lblAddress);
JTextArea txtAddress = new JTextArea();
txtAddress.setBorder(BorderFactory.createLineBorder(Color.black));
txtAddress.setLineWrap(true);
txtAddress.setWrapStyleWord(true);
JScrollPane scrollPane = new JScrollPane(txtAddress,
JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
scrollPane.setPreferredSize(new Dimension(250, 100));
panel.add(scrollPane);
layout.putConstraint(SpringLayout.WEST, lblName,
0,
SpringLayout.WEST, panel);
layout.putConstraint(SpringLayout.NORTH, lblAddress,
10,
SpringLayout.SOUTH, lblName);
layout.putConstraint(SpringLayout.WEST, txtName,
25,
SpringLayout.EAST, lblName);
layout.putConstraint(SpringLayout.NORTH, scrollPane,
10,
SpringLayout.SOUTH, lblAddress);
int result = JOptionPane.showConfirmDialog(frame, panel,
"Text Box and Text Area Example", JOptionPane.OK_CANCEL_OPTION,
JOptionPane.PLAIN_MESSAGE);
if (result == JOptionPane.YES_OPTION) {
System.out
.println(txtName.getText() + ",\n" + txtAddress.getText());
} else {
System.out.println("Canceled");
}
System.exit(0);
}
}
However, I suggest its better you use a JDialog instead of the JOptionPane for complex input forms like these.