You are on the right lines; you just need to use showConfirmDialog instead of showMessageDialog , which allows you to pass any Component as your "message" and display it in JDialog . You can then capture the contents of JTextArea if the user clicks OK; eg.
int okCxl = JOptionPane.showConfirmDialog(SwingUtilities.getWindowAncestor(this), textArea, "Enter Data", JOptionPane.OK_CANCEL_OPTION) if (okCxl == JOptionPane.OK_OPTION) { String text = textArea.getText();
If you want to show JLabel in conjunction with your JTextArea , you can create and pass to JPanel , containing as Component s; eg.
JTextArea textArea = ... JPanel pnl = new JPanel(new BorderLayout()); pnl.add(new JLabel("Please enter some data:"), BorderLayout.NORTH); pnl.add(textArea, BorderLayout.CENTER); JOptionPane.show...
Adamski
source share