Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Show Dialog with TextArea & Buttons

 
Unnsse Khan
Ranch Hand
Posts: 511
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 511
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 138
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Unnsse,

You could use JFrameBuilder to make some examples of a TextArea that is embedded inside the Dialog by yourself.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic