File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Swing / AWT / SWT and the fly likes Show Dialog with TextArea & Buttons Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Show Dialog with TextArea & Buttons" Watch "Show Dialog with TextArea & Buttons" New topic

Show Dialog with TextArea & Buttons

Unnsse Khan
Ranch Hand

Joined: Nov 12, 2001
Posts: 511
I am using the JOptionPane to show a small dialog box... How do I show a custom dialog box (or another frame) which contains a TextArea and two buttons? Sorry, I'm a Swing dummy

Here's where the code is executed:

taskDescription.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
JOptionPane.showInternalInputDialog(desk, "Enter Description");

Any help, tips, suggestions, will be greatly appreciated....

With thanks,
Kriti Garg
Ranch Hand

Joined: Sep 13, 2004
Posts: 50

We can add Components to the options array of the JOptionDialog whc is actually an object array.

....Sample Code.....

package abc;

import javax.swing.*;
import java.awt.*;
//import javax.swing.event.*;
import java.awt.event.*;

public class OptionDlg
extends JFrame {
// JOptionPane optionPane = null;
public OptionDlg() {

this.setSize(new Dimension(300, 300));
JButton btn = new JButton("Click");
btn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Object options[] = {
new JTextField("Text Field"),new JButton("Button")};

int stopOption = JOptionPane.showOptionDialog(null,
"Option Dialog",
"Option Dialog", JOptionPane.DEFAULT_OPTION,
options, options[0]);



public static void main(String[] args) {
OptionDlg optionDlg1 = new OptionDlg();


U can also use your own JDialog and JFrame instead of thisnd ur componentns like Textfiled or button to this.

Unnsse Khan
Ranch Hand

Joined: Nov 12, 2001
Posts: 511
This is a good example, thank you...

Can you show me an example of a TextArea that is embedded inside the Dialog??
Pat Hays
Ranch Hand

Joined: Aug 20, 2004
Posts: 138
Hi Unnsse,

You could use JFrameBuilder to make some examples of a TextArea that is embedded inside the Dialog by yourself.

Download Java GUI Builder, <a href="" target="_blank" rel="nofollow"></a>
I agree. Here's the link:
subject: Show Dialog with TextArea & Buttons
It's not a secret anymore!