java - Popup JDialog 是否有默认的 java 类?

标签 java swing popupwindow jdialog

我一直在使用此代码来实现 Popup JDialog 之类的内容,就像您在防病毒软件扫描系统或更新自身时所看到的那样:

import java.awt.*;
import javax.swing.JDialog;
import javax.swing.JLabel;

public class PopupDialog extends JDialog {

    public PopupDialog() throws HeadlessException {
        createUI();
    }

    public static void main(String[] args) {
        EventQueue.invokeLater(new Runnable() {

            @Override
            public void run() {
                PopupDialog popupDialog = new PopupDialog();
                popupDialog.setVisible(true);
            }
        });
    }

    private void createUI() {
        setTitle("Popup Dialog");
        setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);

        addComponentsToFrame();

        //This call will give screens viable area, which takes into account the taskbar, which could be at the bottom, top,left or right of the screen.
        Rectangle maxBounds = GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds();

        //get screen size
        int sWidth = maxBounds.width, sHeight = maxBounds.height;

        setSize(275, 225);//set frame size
        Dimension appDim = getSize();
        //get app size
        int aWidth = appDim.width, aHeight = appDim.height;

        //set location like a tooltip would be except its a custom dialog like an AV
        setLocation(sWidth - aWidth, (sHeight - aHeight));
    }

    private void addComponentsToFrame() {
        JLabel label = new JLabel("Popup Dialog");
        getContentPane().add(label, BorderLayout.CENTER);
    }
}

但我的问题是:java中是否有任何类或包可以为我做到这一点?如果不是,我将如何允许 JDialog 从任务栏(或屏幕外)向上滑动?或者以某种方式以缓慢的方式变得可见,就像系统托盘中的工具提示弹出窗口一样。谢谢。

编辑我想使用 JDialog 或 Frame 的原因是因为我希望能够使用 setUndecorated(true); 完全设置弹出窗口的外观并添加自定义退出图标、背景等

最佳答案

关于java - Popup JDialog 是否有默认的 java 类?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11092549/

相关文章:

java - 在环境中设置路径后 Gradle 未运行

java - 什么时候可以在 Java 中使用 Thead.stop() ?

javascript - 使用特定浏览器的弹出窗口

security - 浏览器窗口弹出窗口 - 风险和特殊功能

java - 如何调试 Wicket 口异常

java - Spring Security @Secured 注解和用户权限

java - 更新 MySQL : java. sql.SQLException:没有为参数 8 指定值

java - SWT 为何比 Swing 快?

java - 按键绑定(bind)按钮时按钮不显示

javascript - 阻止弹出窗口打开两次