Hi,
I have created a menuItem & when i press the menuitem a JOptionPane dialog box opens. I want to create a button in a dialog box when menuitem is clicked. I am not interested in JOptionPane. But my example code JOptionPane. Can somebody please guide me how to create a button in a dialog box?
import java.awt.*;
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
public class MainMenu2 implements ActionListener {
JFrame f;
JMenuBar jmb;
JMenu jmFile;
JMenuItem jmiOpen;
MainMenu2() {
f = new JFrame("Menu Demo");
f.setSize(220, 200);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jmb = new JMenuBar();
jmFile = new JMenu("File");
jmiOpen = new JMenuItem("Open");
jmFile.add(jmiOpen);
jmb.add(jmFile);
jmiOpen.addActionListener(this);
f.setJMenuBar(jmb);
f.setVisible(true);
}
public void actionPerformed(ActionEvent ae) {
ShowDialogBox(jmiOpen);
}
public static void main(String args[]) {
new MainMenu();
}
void ShowDialogBox(Component parent)
{ //JFrame f = new JFrame();
JOptionPane pane = new JOptionPane(
"New label", JOptionPane.QUESTION_MESSAGE
);
pane.setWantsInput(true);
JDialog dialog = pane.createDialog(parent, "Enter Text");
// Uncomment line and comment out next
// to see application modal
JButton btn= new JButton("Send");
btn.addActionListener(this);
//pane.add(btn);
dialog.add(btn);
dialog.setModalityType(
Dialog.ModalityType.APPLICATION_MODAL);
dialog.setModalityType(
Dialog.ModalityType.DOCUMENT_MODAL);
dialog.setVisible(true);
}
}
Right now its creating a JOptionPane style dialog box with OK button. I want to put a "send" button also.
Zulfi.