在任务栏上显示JDialog看起来不太好 [英] Showing JDialog on taskbar does not look good

查看:86
本文介绍了在任务栏上显示JDialog看起来不太好的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

关注这些帖子在任务栏中显示JDialog不起作用在任务栏上显示JDialog 我试图在任务栏上显示我的JDialog.尽管可以,但是这种行为很奇怪,而且看起来也不好.

Following the posts Showing JDialog in taskbar not working and Show JDialog on taskbar I have tried to show my JDialog in the taskbar. Although it worked, the behaviour is strange and it does not look good.

因此,任务栏中会出现一个按钮,但是当我单击它时,桌面的左上角会出现一个小窗口.该窗口非常小,以致于其内容不可见.当我放大它时,我可以看到它是空的.我的JDialog仅在关闭此窗口后出现.

So a button appears in the taskbar, but when I click on it a small window appears in the top left corner of my desktop. This window is so small that its content is not visible. When I enlarge it I can see it's empty. My JDialog only appears after I close this window.

是否可以摆脱该窗口或将我的JDialog嵌入其中?

public class SelectionDialog extends JDialog{

 private static final long serialVersionUID = 5677381647525913165L;
 private int response = JOptionPane.NO_OPTION;
 private SelectionFrame frame = null;
 public SelectionDialog(String attachmentName, Long processInstance, String processName) {
  super(new SelectionFrame("Selection"));
  setModalityType(ModalityType.TOOLKIT_MODAL);
  setVisible(true);
  toFront();
  try {
       UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
  } catch (ClassNotFoundException e) {
    e.printStackTrace();
  } catch (InstantiationException e) {
    e.printStackTrace();
  } catch (IllegalAccessException e) {
    e.printStackTrace();
  } catch (UnsupportedLookAndFeelException e) {
   e.printStackTrace();
  }  
    response = JOptionPane.showConfirmDialog(this.getParent(), "Would you like to apply the policy attachment " + attachmentName + " to current instance (" + processInstance + ") of process " + processName + " ?", "Confirm",
            JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
 }

 public void setVisible(boolean visible) {
    super.setVisible(visible);
    if (!visible) {
        ((SelectionFrame)getParent()).dispose();
    }
 }

 public int getUserSelection(){
    return response;
 }
}

框架代码:

public class SelectionFrame extends JFrame{

 private static final long serialVersionUID = -9063300247378170855L;

 SelectionFrame(String title) {
     super(title);
     setUndecorated(true);
     setVisible(true);
     setLocationRelativeTo(null);
 }
}

然后,在我的主应用程序中,我像这样使用它:

Then, inside my main application I use it like this:

SelectionDialog dialog = new SelectionDialog(attachmentDAO.getAttachmentName(), inst.getInstanceId(), this._processId);
int response = dialog.getUserSelection();
if (response == JOptionPane.NO_OPTION) {
 System.out.println("No button clicked");
} else if (response == JOptionPane.YES_OPTION) {
 System.out.println("Yes button clicked");
} else if (response == JOptionPane.CLOSED_OPTION) {
 //System.out.println("JOptionPane closed");
}
dialog.setVisible(false);

我也在这里包括了图片: ! http://tinypic.com/view.php?pic= mslnyq& s = 8#.Uvq17bTpKnc http://tinypic.com/view.php?pic=33mlbty&s = 8

I have also included pictures here: !http://tinypic.com/view.php?pic=mslnyq&s=8#.Uvq17bTpKnc !http://tinypic.com/view.php?pic=33mlbty&s=8

推荐答案

将null强制转换为任何类型都是没有用的.将真实的对象传递给构造函数.

Casting null to any type is useless. Pass a real object to the constructor.

另外,尝试向JDialog添加一些内容(也许是标签)...这样就不会造成大小问题(使用适当的布局管理器).有关JDialog的位置,请参阅如何在屏幕上居中放置JDialog ?或类似的东西.

Also, try adding some content to the JDialog (a label perhaps)... So that sizing won't be an issue (use an appropriate layout-manager). For location of the JDialog, refer to How do I center a JDialog on screen? or something similar.

希望这会有所帮助.

这篇关于在任务栏上显示JDialog看起来不太好的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆