Swing - How to Lock Parent Frame through JWindow
How can we lock Parent Frame (JFrame) through window (JWindow) as we can do it by using JDialog?
If i use the following code then it locks the parent frame
JFrame frameObj= new JFrame(Some Title);
frameObj.getContentPane().add(new JButton("Cannot Press this button if main Frame is locked"));
JDialog objDialog = new JDialog(frameObj,"Child Dialog",true);
objDialog.show();
But if i use the following code, it does not lock the parent frame
JFrame frameObj= new JFrame(Some Title);
frameObj.getContentPane().add(new JButton("This button can be pressed any time now"));
JWindow objWIndow = new JWindow(frameObj);
objWIndow.show();
[708 byte] By [
M0Ja] at [2007-11-26 23:20:38]

# 4
the JDialog is the way to go, but this may answer your initial question
(depending on what you're trying to do)
import javax.swing.*;import java.awt.*;
import java.awt.event.*;
class Testing
{
public void buildGUI()
{
final JFrame f = new JFrame();
JWindow objWIndow = new JWindow(f);
objWIndow.setBounds(100,100,100,100);
JButton btn = new JButton("This button can be pressed any time now");
f.getContentPane().add(btn);
f.pack();
f.setLocationRelativeTo(null);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setEnabled(false);//<
f.setVisible(true);
objWIndow.setVisible(true);
btn.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent ae){
JOptionPane.showMessageDialog(f,"Got me!!");
}
});
}
public static void main(String[] args)
{
SwingUtilities.invokeLater(new Runnable(){
public void run(){
new Testing().buildGUI();
}
});
}
}