Re: JDialogs used with a Window
- From: "Andrew Thompson" <andrewthommo@xxxxxxxxx>
- Date: 14 Jul 2006 04:45:40 -0700
Damn-it! Google lost my entire 1st reply to that.
Here is the extremely abbreviated (and pissed-off) version..
<sscce>
import java.awt.event.*;
import javax.swing.*;
public class ModalOnWindow {
public static void main(String[] args) {
JWindow window = new JWindow();
JButton b = new JButton("Open Dialog");
b.addActionListener( new ActionListener() {
public void actionPerformed(ActionEvent ae) {
JDialog d = new JDialog();
d.getContentPane().add(new JLabel("Hi!"));
d.setModal(true);
d.pack();
d.setLocationRelativeTo(null);
d.setVisible(true);
}
});
window.getContentPane().add(b);
window.pack();
window.setSize( java.awt.Toolkit.
getDefaultToolkit().getScreenSize() );
window.setVisible(true);
}
}
</sscce>
This works.
Yours may not because you had the call to setVisible()
before adding the button. Moving it may fix the problem,
but otherwise please post a short, compilable example
of failing code.
Andrew T.
.
- Follow-Ups:
- Re: JDialogs used with a Window
- From: jackroofman
- Re: JDialogs used with a Window
- From: jackroofman
- Re: JDialogs used with a Window
- References:
- JDialogs used with a Window
- From: jackroofman
- JDialogs used with a Window
- Prev by Date: Re: JDialogs used with a Window
- Next by Date: Re: horizontal separators
- Previous by thread: Re: JDialogs used with a Window
- Next by thread: Re: JDialogs used with a Window
- Index(es):