我一直在使用此代码来实现 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/