可视化网站建设软件,做外贸自己开公司网站,中交路桥建设有限公司中标,定制app开发哪家比较好可以说,我们有几个JFrame窗口同时可见,并且每个窗口都出现JDialog.当我们的窗口处于级联模式和对话框setAlwaysOnTop为真时,所有对话框将在最后一个窗口中可见.我只想将Dialog组件与其所有者关联起来,这样当你在Frames之间切换时,你只会在顶部获得一个对话框,并且在单击一个框架…可以说,我们有几个JFrame窗口同时可见,并且每个窗口都出现JDialog.当我们的窗口处于级联模式和对话框setAlwaysOnTop为真时,所有对话框将在最后一个窗口中可见.我只想将Dialog组件与其所有者关联起来,这样当你在Frames之间切换时,你只会在顶部获得一个对话框,并且在单击一个框架时不会丢失该对话框.对话框有这样的构造函数setAlwaysOnTop(true);setModal(false);提前致谢解决方法:How to make JDialog onTop only for his parent? setParent in the constructor properly必须使用setModalityType f.e. ModalityType.DOCUMENT_MODAL ModalityType.APPLICATION_MODAL而不是setModal setModal对初始化/是此JDialog的父级的容器有效不要使用多个JFrame,而是使用JDialog,将此容器重新用于其他操作例如import java.awt.*;import java.awt.event.*;import javax.swing.*;public class SuperConstructor extends JFrame {private static final long serialVersionUID 1L;public SuperConstructor() {setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);setPreferredSize(new Dimension(300, 300));setTitle(Super constructor);Container cp getContentPane();JButton b new JButton(Show dialog);b.addActionListener(new ActionListener() {Overridepublic void actionPerformed(ActionEvent evt) {FirstDialog firstDialog new FirstDialog(SuperConstructor.this);}});cp.add(b, BorderLayout.SOUTH);JButton bClose new JButton(Close);bClose.addActionListener(new ActionListener() {Overridepublic void actionPerformed(ActionEvent evt) {System.exit(0);}});add(bClose, BorderLayout.NORTH);pack();setVisible(true);}public static void main(String args[]) {EventQueue.invokeLater(new Runnable() {Overridepublic void run() {SuperConstructor superConstructor new SuperConstructor();}});}private class FirstDialog extends JDialog {private static final long serialVersionUID 1L;FirstDialog(final Frame parent) {super(parent, FirstDialog);setPreferredSize(new Dimension(200, 200));setLocationRelativeTo(parent);setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);setModalityType(Dialog.ModalityType.APPLICATION_MODAL);JButton bNext new JButton(Show next dialog);bNext.addActionListener(new ActionListener() {Overridepublic void actionPerformed(ActionEvent evt) {SecondDialog secondDialog new SecondDialog(parent, false);}});add(bNext, BorderLayout.NORTH);JButton bClose new JButton(Close);bClose.addActionListener(new ActionListener() {Overridepublic void actionPerformed(ActionEvent evt) {setVisible(false);}});add(bClose, BorderLayout.SOUTH);pack();setVisible(true);}}private int i;private class SecondDialog extends JDialog {private static final long serialVersionUID 1L;SecondDialog(final Frame parent, boolean modal) {//super(parent); // Makes this dialog unfocusable as long as FirstDialog is visiblesetPreferredSize(new Dimension(200, 200));setLocation(300, 50);setModal(modal);setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);setTitle(SecondDialog (i));setModalityType(Dialog.ModalityType.APPLICATION_MODAL);JButton bClose new JButton(Close);bClose.addActionListener(new ActionListener() {Overridepublic void actionPerformed(ActionEvent evt) {setVisible(false);}});add(bClose, BorderLayout.SOUTH);pack();setVisible(true);}}}标签java,modal-dialog,swing,jdialog来源 https://codeday.me/bug/20190529/1179407.html