ActionListener in JDialog created by JOptionPane

I have a problem I absolutely cannot get around. I've been toying with this code all day and nedd some help badly. The code is posted below. Let me give you some background. I have an application that uses "popups" to ask the user a series of questions. I have two bg images I want to display for the background,

as well as a custom button (that's no sweat). I originally wrote a class extending JDialog to show the popups. But JDialog does not "block" and wait for user input. I started toying around with JOptionPane. I have created a JDialog from JOptionPane.createDialog(parent, title). All the components display correctly and

the dialog blocks, BUT the actionListener I added to my button does not go into action. Am I barking up the wrong tree, or is there a way to get a JDialog to block

the running thread?

class myDialog{

JDialog main;

JTextField inputfield;

public myDialog(JFrame parent, String display){

main = this.createDialog(parent,"hello");

Dimension screenSize =new Dimension(Toolkit.getDefaultToolkit().getScreenSize());

main.setBounds(screenSize.width/2 - 195,

screenSize.height/2 - 50,395,110);

JLabel textInsert =new JLabel(display);

textInsert.setFont(new Font("Serif", Font.BOLD|Font.ITALIC, 14));

textInsert.setForeground(Color.gray);

JButton next =new JButton(new ImageIcon("images/gui/next.png"));

inputfield =new JTextField(20);

Container c = main.getContentPane();

c.setLayout(new BorderLayout());

c.removeAll();// call this to remove the components added by JOptionPane.

BackgroundComponent panel =new BackgroundComponent(new ImageIcon("images/gui/upperdialog.png").getImage());

BackgroundComponent panel2 =new BackgroundComponent(new ImageIcon("images/gui/lowerdialog.png").getImage());

panel.add(new JLabel(new ImageIcon("images/gui/spacer.png")));

panel.add(textInsert);

panel2.add(inputfield);

panel2.add(next);

c.add(panel, BorderLayout.NORTH);

c.add(panel2, BorderLayout.CENTER);

main.setResizable(true);

main.setVisible(true);

next.addActionListener(new ActionListener(){

publicvoid actionPerformed(ActionEvent e){

main.setVisible(false);

}

});///////////////////////////////////////

}

}

Thanx in advance -- CSB

[3507 byte] By [crazystaceyba] at [2007-10-1 3:23:56]
# 1

> the wrong tree, or is there a way to get a JDialog to

> block

> the running thread?

Yes, by making it modal:

main.setModal(true);

main.setVisible(true);

There are also a couple of JDialog constructors that you can use to create a modal dialog without having to use the setModal method.

Torgila at 2007-7-8 22:04:50 > top of Java-index,Archived Forums,Java 2 Software Development Kit (J2SE SDK)...
# 2
Thank you for the reply Torgil. You know, I thought I tried setting the dialog to modal yesterday, and it wouldn't work. I just gave it a go, and VOILA! it works. Thanks for help. My dukes go you.
crazystaceyba at 2007-7-8 22:04:50 > top of Java-index,Archived Forums,Java 2 Software Development Kit (J2SE SDK)...
# 3
You're welcome!
Torgila at 2007-7-8 22:04:50 > top of Java-index,Archived Forums,Java 2 Software Development Kit (J2SE SDK)...