如何禁用对话框中的 X?
有没有办法禁用对话框上的所有 X?
我可以通过以下方式完成这一任务:
JOptionPane pane = new JOptionPane("Are you hungry?", JOptionPane.QUESTION_MESSAGE, JOptionPane.YES_NO_OPTION);
JDialog dialog = pane.createDialog("Title");
dialog.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent evt) {
} });
dialog.setContentPane(pane);
dialog.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
dialog.pack();
但问题是我必须将其应用到其他 20-40 个对话框,这将非常耗时。
所以我想知道如何用一行代码来制作字体所有对话框上都更大(如下所示),有没有办法禁用 X 功能。
UIManager.put("OptionPane.messageFont", 新的 FontUIResource(新 字体(“ARIAL”,Font.BOLD,30)));
Is there a way to disable all X on dialog boxes?
I can accomplish this on one by doing:
JOptionPane pane = new JOptionPane("Are you hungry?", JOptionPane.QUESTION_MESSAGE, JOptionPane.YES_NO_OPTION);
JDialog dialog = pane.createDialog("Title");
dialog.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent evt) {
} });
dialog.setContentPane(pane);
dialog.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
dialog.pack();
But the problem is thst I have to apply this to other 20-40 dialog boxes which will be time consuming..
So I was wondering just how you can do one line of code to make the fonts bigger on all the Dialog boxes (shown below), is there a way to for the X disable feature.
UIManager.put("OptionPane.messageFont",
new FontUIResource(new
Font("ARIAL",Font.BOLD,30)));
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
为什么不创建一个扩展 JDialog 的自定义类,在构造函数中设置您想要的关闭行为?
Crtl+F 将 JDialog 替换为 NoCloseDialog ...
Why not just create a custom class that extends the JDialog setting your desired close behavior in the constructor?
Crtl+F Replace JDialog with NoCloseDialog ...
JDialog
方法setDefaultCloseOperation
的工作方式与 JFrame 的类似:http://download.oracle.com/javase/6/docs/api/javax/swing/JDialog.html#setDefaultCloseOperation(int)
两者都不会对于所有框架,它只会对它所设置的实例执行此操作。如果您想应用于所有对话框,您需要执行以下操作之一:
JDialog
methodsetDefaultCloseOperation
works just like JFrame's:http://download.oracle.com/javase/6/docs/api/javax/swing/JDialog.html#setDefaultCloseOperation(int)
Neither will do this for all frames, it will just do it for the instance it is set on. If you want to apply to all your dialogs you need to do one of the following:
您需要添加一个 windowListener,还需要设置对话框的默认关闭操作。
You need to add a windowListener but also set the default close operation for the dialog.
您应该将其删除,而不是禁用该控件。用户不应该看到“X”按钮,然后让它表现得不像他们期望的那样。
请参阅:
Rather than disable a control, you should remove it. Users shouldn't see an "X" button and then have it not behave like they expect.
See: