manav
manav

Reputation: 119

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

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.

Upvotes: 2

Views: 1080

Answers (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);

        // ...
}

Upvotes: 0

Andrew Thompson
Andrew Thompson

Reputation: 168825

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.

Upvotes: 2

user784540
user784540

Reputation:

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

Multiple Document Interfaces with JDesktopPane and JInternalFrame

Upvotes: 2

Related Questions