| Other | Other |
|---|---|
| 1.1.8 1.1.8Fixed | 1.2.0Fixed |
|
Duplicate :
|
|
|
Duplicate :
|
|
|
Relates :
|
|
|
Relates :
|
The following application displays a JDialog that is created by the
following constructor:
new JDialog(new JFrame(), "Modal Dialog", true)
The dialog created by this application is modal on Windows NT, but not
on Solaris.
=========================================================================
/*
* ModalDialogTest.java
* JDialog created with modality parameter set to true is not modal on
* Solaris
*
*/
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.GridLayout;
import java.awt.event.*;
import java.awt.swing.*;
public class ModalDialogTest extends JPanel implements ActionListener {
JDialog dialog = new JDialog(new JFrame(), "Modal Dialog", true);
public static void main( String[] argv ) {
new ModalDialogTest();
}
public ModalDialogTest() {
JFrame frame = new JFrame("Modal Dialog Test");
JPanel controlPanel = new JPanel();
JPanel infoPanel = new JPanel();
JButton showButton = new JButton("Show Modal Dialog");
JButton testButton = new JButton("Test");
frame.getContentPane().setLayout(new BorderLayout());
infoPanel.setLayout(new GridLayout(0,1));
showButton.setOpaque(true);
showButton.setBackground(Color.yellow);
testButton.setOpaque(true);
testButton.setBackground(Color.pink);
controlPanel.add(showButton);
controlPanel.add(testButton);
infoPanel.add(new JLabel("Click the \"Show Modal Dialog\" button to display a modal JDialog."));
infoPanel.add(new JLabel("Click the \"Test\" button to verify dialog modality."));
frame.getContentPane().add(BorderLayout.NORTH, controlPanel);
frame.getContentPane().add(BorderLayout.SOUTH, infoPanel);
dialog.setSize(200,200);
showButton.addActionListener(this);
testButton.addActionListener(this);
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {System.exit(0);}
public void windowClosed(WindowEvent e) {System.exit(0);}
});
frame.pack();
frame.setSize(450, 120);
frame.setVisible(true);
}
public void actionPerformed(ActionEvent evt) {
String command = evt.getActionCommand();
if (command == "Show Modal Dialog") {
System.out.println("*** Invoking JDialog.show() ***");
dialog.setLocation(200,200);
dialog.show();
}
else if (command == "Test") {
System.out.println("*** Test ***");
}
}
}
=========================================================================
|