• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

Dialog box problems :(

 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everyone -
I've got a program with a frame as the parent window. The user enters some data into fields and I do a check to see if any of the fields have been left empty. If any have, I want a small dialog box to pop up saying "You forgot to fill 'n' window" .. I created the dialog box (modal) and a window listener so that when the user presses the X on the dialog box, it will close it. However, I CAN'T for the life of me get the "error" dialog box I created to CLOSE!!
In the 'window_closing' function I've tried:
dispose();
hide();
setVisible(false);
Here's my code for the box:
// Created outside the function
Dialog error = new Dialog(window, "Error", true);
public void PopUpError() {
error.setSize(200, 200);
error.show();

error.addWindowListener( new WindowAdapter() {
public void windowClosing( WindowEvent e )
{
error.dispose();
}
} );

HELP! This is probably easy and I just am not seeing it.

}
------------------
Eric Neuman
Sun Certified Programmer for the Java� 2 Platform
------------------
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why not use Swing components!? :-)
It seems somehow that AWT Dialog with Modal mode cannot catch
WindowClosing event.
Could someone tell me why and how(mechanism)?
Note:
JDialog need not to attach the Listener !!
I hope my sample test code can help you.
-------------------
/*
Dialog Problem : 2001.05.10 Reproduction
*/
import java.lang.*;
import java.io.*;
import java.util.*;
import java.text.* ;
import java.math.* ;
import java.applet.* ;
import java.awt.* ;
import java.awt.event.* ;
import javax.swing.* ;
public class testpad {
/** Main Function */
public static void main(String[] args) {
JFrame w = new JFrame("TestPad Frame") ;
//Frame w = new Frame("TestPad Frame") ;
w.addWindowListener( new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.out.println("Frame Close....") ;
System.exit(0) ;
}
}
) ;
w.pack() ;
w.setSize( 200,200 ) ;
Dimension screen = Toolkit.getDefaultToolkit().getScreenSize() ;
w.setLocation( (screen.width - w.getSize().width) / 2 ,
(screen.height - w.getSize().height) / 2 ) ;
w.setVisible(true) ;
Frame wf = new Frame() ; // WorkFrame for TmpDialog
// (in order to close only TmpDialog)
//TmpDialog tp = new TmpDialog(wf,"Error",false) ; // Non-Modal
TmpDialog tp = new TmpDialog(wf,"Error",true) ; // Modal
//tp.addWindowListener( new WindowAdapter(){
// public void windowClosing(WindowEvent e){
// System.out.println("TmpDialog Close....") ;
// ((Frame)((Dialog)e.getSource()).getParent()).dispose() ;
// }
// }
// ) ;
}
}
class TmpDialog extends JDialog {
//class TmpDialog extends Dialog {
TmpDialog(Frame wf , String title , boolean bMode) {
super(wf,title,bMode) ;
System.out.println("TmpPanel() Constructor....") ;
Dimension screen = Toolkit.getDefaultToolkit().getScreenSize() ;
JLabel jl1 = new JLabel("Please wait a while",JLabel.CENTER) ;
//Label jl1 = new Label("Please wait a while",Label.CENTER) ;
jl1.setOpaque(true) ;
jl1.setForeground(Color.white) ;
jl1.setBackground(Color.blue) ;
this.getContentPane().add(jl1) ;
//add(jl1) ;
this.pack() ;
this.setSize(300,80) ;
this.setLocation( (screen.width - this.getSize().width) / 2 ,
(screen.height - this.getSize().height) / 2 ) ;
this.toFront() ;
this.setVisible(true) ;
}
}

---------------------------------------
Without a hurt,the heart is hollow....
I like this English maxim. :-)
---------------------------------------

------------------
I am very happy to find this site.
 
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Eric, since you just want to show the error message, you can use an inbuilt swing message dialog by using the following:
JOpeionPane.showMessageDialog(parent, message, title, DialogType)
for example:
JOptionPane.showMessageDialog(this, "Please fill all fields!", "Error", JOptionPane.ERROR_MESSAGE);
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!