问题
This question has been asked previously but from what I have found, the questions and responses are from a few years ago and hoping there is updated/new information.
The same code works on Windows as it displays the X in the top right corner. On Linux, nothing appears in the top right corner. Windows is using JDK 1.8.0_60 Linux is using 1.8.0_111-b15
Based on the research, this issue is known to exist on varying flavors of Linux.
import javax.swing.JDialog;
public class JDialogSimple{
private JDialog dialog = new JDialog();
public JDialogSimple() {
dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
dialog.setModal(true);
dialog.pack();
dialog.setLocation(200, 200);
dialog.setSize(400, 400);
dialog.setTitle("Test Dialog");
dialog.setVisible(true);
}
public static void main(String args[]) {
JDialogSimple colourDialog = new JDialogSimple();
}
}
Has any new information come about related to this? Is this now the accepted behavior on the Linux platform?
回答1:
I noticed the one thread that posts an answer has the following :
super(null, title, Dialog.ModalityType.MODELESS);
I think it should have been the following :
super(null, title, Dialog.ModalityType.APPLICATION_MODAL);
For my test, changing the above from MODELESS to APPLICATION_MODAL, the Linux JDialog now showed the X to close the window.
来源:https://stackoverflow.com/questions/46428634/jdialog-not-showing-minimize-close-button-on-linux