我一直在使用此代码来实现某种功能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中是否有任何类或包可以为我做到这一点?如果不是,我将如何允许 JDialogslide
从任务栏(或屏幕外)启动?或者以某种方式以缓慢的方式变得可见,就像ToolTip
系统托盘中的弹出窗口一样。谢谢。
编辑我想使用 JDialog 或 Frame 的原因是因为我希望能够完全皮肤弹出窗口,使用setUndecorated(true);
和添加自定义退出图标、背景等