This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Show Dialog with TextArea & Buttons" Watch "Show Dialog with TextArea & Buttons" New topic
Author

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
Hi,

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");
this.getContentPane().add(btn);
this.setVisible(true);
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,
JOptionPane.QUESTION_MESSAGE, null,
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.

Bbye
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="http://www.mars3000.com" target="_blank" rel="nofollow">http://www.mars3000.com</a>
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Show Dialog with TextArea & Buttons
 
Similar Threads
Dynamically setting TextArea size
Value in the textarea is not retaining in jquery popup modal.
How to Get a String from a Text Area?
nx: contractor - max please help
textarea