Hi,
I tried that but the dialog boxes are not getting captured. I am basically looking to capture the dialogs that pop up. Similar to what getWindows does in 1.6
Please find the code using ComponentListener appended.
public class SwingSample implements ContainerListener, ComponentListener, ActionListener{
/**
* Sample swing application to try various functions on Dialog Boxes
* @author kiranc
* @version June 19
*/
JFrame jF = new JFrame();
JPanel panel = new JPanel();
JTextField txtfield = new JTextField (10);
JButton OkButton = new JButton ("Click Me");
JLabel Login = new JLabel ("LogIn:");
JDialog jD = new JDialog(jF,"Title: test");
public void actionPerformed(ActionEvent e){
System.out.println("ButtonClicked");
JOptionPane.showMessageDialog(panel, "Did the component event happen?");
panel.revalidate();
}
public void componentMoved(ComponentEvent e)
{
System.out.println("Moved");
}
public void componentHidden(ComponentEvent e)
{
System.out.println("Hidden");
}
public void componentResized(ComponentEvent e)
{
System.out.println("Resized");
}
public void componentShown(ComponentEvent e)
{
System.out.println("Shown");
}
public void componentAdded(ContainerEvent e)
{
e.getChild();
System.out.println("Added");
}
public void componentRemoved(ContainerEvent e)
{
e.getChild();
System.out.println("Removed");
}
public SwingSample() {
panel.setBounds(0, 0, 1400, 1500);
Login.setBounds (200, 150, 40,40);
panel.add(Login);
txtfield.setBounds (250, 160, 60,20);
panel.add(txtfield);
OkButton.setText("click");
OkButton.setBounds (225, 200, 10,40);
OkButton.setPreferredSize(new Dimension(200, 80));
OkButton.addActionListener(this);
panel.add(OkButton, BorderLayout.CENTER);
JComponent newContentPane = panel;
newContentPane.setOpaque(true); //content panes must be opaque
jF.setContentPane(panel);
jF.addComponentListener(this);
//panel.addContainerListener(this);
panel.addComponentListener(this);
}
public static void main (String []args) {
SwingSample lgform = new SwingSample ();
lgform.jF.pack();
lgform.jF.setVisible(true);
System.out.println("Printing before confirm dialog");
/* winArray= Window.getWindows();
for(int i =0;i < winArray.length;i++){
System.out.println(i+":"+winArray[i].toString());
}*/
//Dialog box 1 with null parent
JOptionPane.showConfirmDialog(null, "Confirm");
//lgform.jF.update(Graphics g);
System.out.println("Printing after confirm dialog");
//Dialog box 2 with parent
JOptionPane.showMessageDialog(lgform.panel, "Message");
lgform.panel.revalidate(); //trying to kinda refresh.
System.out.println("Printing after Message dialog");
JButton newButton = new JButton("JButton #");
lgform.panel.add(newButton);
lgform.panel.revalidate(); //Makes the button show up.
}
}
}