how to restrict more than one java application icon on taskbar?

流过昼夜 提交于 2019-12-24 03:18:45

问题


I have created an application in java which have several forms. During application start getting open new form on button click event,On windows's taskbar the number of icons of that form getting increases. what I want is only applicatoin icon should be displayed on task bar whether one form is open or more than one.


回答1:


The problem happens because each JFrame gets a task-bar icon. See The Use of Multiple JFrames, Good/Bad Practice? for links to a multitude of solutions.




回答2:


I think this tutorial will help you to solve your task.

Multiple Document Interfaces with JDesktopPane and JInternalFrame




回答3:


If you already have your new window as a JDialog and are still facing the problem of having two icons in the taskbar, it may be that you are creating your modal JDialog like this:

JDialog dialog = new JDialog((JFrame) null, true);

With owner (first) argument set to null, the application creates a new icon in the taskbar for the dialog. So, to avoid this, just pass the reference to your frame to the dialog constructor when opening the dialog (e.g. by clicking on a button). Like this:

public class MyBrandNewDialog {

    public MyBrandNewDialog(JFrame owner) {

        // create new modal dialog (the second argument is for modality)
        JDialog dialog = new JDialog(owner, true);

        // ...
}


来源:https://stackoverflow.com/questions/12086600/how-to-restrict-more-than-one-java-application-icon-on-taskbar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!