swing中new一个dialog使之与父窗体锁定
展开全部
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
public class Test {
public static void main(String[] args) {
final MyFrame frame = new MyFrame();
JButton button = new JButton("确定");
frame.add(button, BorderLayout.SOUTH);
button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
JDialog dialog = new JDialog(frame, "Dialog", true);
dialog.setSize(300, 200);
dialog.setAlwaysOnTop(true);
dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
dialog.setVisible(true);
}
});
}
}
class MyFrame extends JFrame {
public MyFrame() {
setTitle("Frame");
setAlwaysOnTop(true);
setVisible(true);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setSize(300, 200);
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询