A dialog itself cannot have a task bar entry, but you can construct a frame that does not have any visible effect and use it as a parent for the dialog. Then it will look like the dialog has a task bar entry. The following code shows you how to do it:
class MyDialog extends JDialog {
private static final List<Image> ICONS = Arrays.asList(
new ImageIcon("icon_16.png").getImage(),
new ImageIcon("icon_32.png").getImage(),
new ImageIcon("icon_64.png").getImage());
MyDialog() {
super(new DummyFrame("Name on task bar", ICONS));
}
public void setVisible(boolean visible) {
super.setVisible(visible);
if (!visible) {
((DummyFrame)getParent()).dispose();
}
}
}
class DummyFrame extends JFrame {
DummyFrame(String title, List<? extends Image> iconImages) {
super(title);
setUndecorated(true);
setVisible(true);
setLocationRelativeTo(null);
setIconImages(iconImages);
}
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…