ICode9

精准搜索请尝试: 精确搜索
首页 > 编程语言> 文章详细

java-通过代码处理JDialog,不要让用户关闭它

2019-12-01 13:02:24  阅读:386  来源: 互联网

标签:jdialog swing dispose java


我有一个简短的代码,我想设置一个对话框,但不希望用户能够关闭它,它只是行不通,请帮助我.

    import javax.swing.*;
    public class Processing extends JOptionPane{

    JDialog jd;
    public Processing(){
        super(null, JOptionPane.DEFAULT_OPTION, 
                  JOptionPane.INFORMATION_MESSAGE, null, new Object[]{});
        Icon processPic = new ImageIcon("C:\\Users\\Judit\\Desktop\\Mesekocka3D"
                + "\\externals\\pics\\szamitas.gif");

        setMessage(processPic);
        jd = createDialog("Számítás");

        jd.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
        jd.setVisible(true);
        jd.dispose();
    }   
}

这是我的代码现在的样子,我使用Jdialog而不是Joptionpane,我是否应该写更多字符以使网站接受我的编辑?

import javax.swing.*;



public class Mifasz
{
 private static class Processing extends JDialog{

public Processing(){
    Icon processPic = new ImageIcon("C:\\Users\\Judit\\Desktop\\Mesekocka3D"
            + "\\externals\\pics\\szamitas.gif");
    JLabel label = new JLabel(processPic);
    add(label);
    setTitle("Számítás");
    setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);        
    setSize(400, 70);
    setLocation(330, 300);
    setModal(true);
    setVisible(true);
    dispose();
}       
}

  public static void main(String[] args)
  {
    Processing pc = new Processing();
  }

}

解决方法:

I’d like to show a gif for the user for a short time, it’s like a loadingscreen, I don’t want him to do anything with the app till, so I’m using joptionpane, but I would also like to disable the X button, so I’m using jdialog, becouse I didn’t find an option to disable the optionpane’s X button.

1)您可以使用未修饰的JDialog#setUndecorated(true);

2)将gif作为Icon放入JLabel

3)使用Swing Timer进行计时,Swing Timer的输出可以是Swing Action并在actionPerformed内放置JDialog#setVisible(fasle);

编辑

i’d like to block it, and it need to be used as many times the user clicks on a JCombobox item

1)仅创建一次JDialog,您将仅重用一次

2)以预期的延迟运行Swing Timer#repeat(false),在actionPerformed中放置JDialog#setVisible(fasle);

3)在选定项目(JComboBox)的事件上更改JLabel myLabel#setIcon(myAnotherGIF)中的图标

4)在invokeLater内部包装JDialog#setVisible(true);

5)不需要任何其他步骤

仅在特殊情况下

6)你必须打电话

myIcon.getImage().flush();
myLabel.setIcon(myIcon);

如果您在JLabel中对Icon的重新绘制有疑问

标签:jdialog,swing,dispose,java
来源: https://codeday.me/bug/20191201/2080853.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有