4

I'm trying to develop my own application for placing notes on the desktop (similar to Sticky Notes under Windows OS). Everything is working nicely but I am still facing a problem: since I want the application to be as "minimal" as possible, I would like it not to appear in the taskbar, so that it doesn't bother the user. Eventually, I would like it to appear in the system tray but, for the moment, this is not the point. To make the application cross-platform, I am developing it in Java, and I read that in order not to make it appear in the taskbar one could use a JDialog. Now my class is

public class NoteWindow extends JDialog implements WindowListener, WindowFocusListener, KeyListener, ComponentListener,
        MouseMotionListener, MouseListener

and in the code I also put

setType(Type.UTILITY);
setBounds(100, 100, 235, 235);
getContentPane().setLayout(null);
setUndecorated(true);

but it doesn't seem to be working: under Linux Mint 17.2 I still see the windows (each window corresponding to a note) in the taskbar (or its equivalent under Linux).

Am I missing something?

EDIT

I post an image to show what I mean, and what I would like not to see:

screenshot

Community
  • 1
  • 1
minomic
  • 645
  • 1
  • 9
  • 22
  • And what about under Windows OS ? – caps lock Sep 21 '15 at 20:44
  • @capslock I don't know since on my notebook I just have Linux Mint and, at the moment, I don't have a Windows machine that I can use – minomic Sep 21 '15 at 20:45
  • Have you tried using a JWindow instead of JDialog? – MadProgrammer Sep 21 '15 at 21:11
  • `getContentPane().setLayout(null);` Java GUIs have to work on different OS', screen size, screen resolution etc. using different PLAFs in different locales. As such, they are not conducive to pixel perfect layout. Instead use layout managers, or [combinations of them](http://stackoverflow.com/a/5630271/418556) along with layout padding and borders for [white space](http://stackoverflow.com/a/17874718/418556). – Andrew Thompson Sep 21 '15 at 23:19
  • @MadProgrammer no I didn't. Do you think this is the problem? – minomic Sep 22 '15 at 06:15
  • 1
    I don't know, I don't use Linux, but `JWindow` typically doesn't present a item on the task bar...expect on MacOS, but that's because you need to ask for "special permission" not to appear on the dock...way work here, may not, give it a try – MadProgrammer Sep 22 '15 at 06:16
  • @MadProgrammer OK I will. Thanks – minomic Sep 22 '15 at 06:17
  • @minomic did you ever fix this problem? i've got the same problem with mint: JDialog, JWindow.. wont work – lynx Apr 09 '18 at 16:34
  • @lynx No, I had given up on this. I'm sorry I can't help more... – minomic Apr 09 '18 at 20:58
  • I'm having a similar problem too. I'm trying to port a C# note taking application I made a few years ago to Java, the primary reason being that I want it to work on Linux along with Windows (C# doesn't seem to be very platform-agnostic). The icon does not appear, but when I activate a note, it activates the secondary notebook window. – TheKodeToad Jan 09 '22 at 11:23

1 Answers1

0

A JDialog should be attached to a JFrame parent. Then the dialog will not have a corresponding button in the taskbar. So, I suggest creating a JFrame instance but not making it visible. In the Sticky Notes example, each note window would have the same parent.

package com.thomaskuenneth;

import javax.swing.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

public class DialogDemo {

    public static void main(String[] args) {
        JFrame parent = new JFrame();
        JDialog d = new JDialog(parent, "Hello");
        d.setBounds(50, 50, 200, 200);
        d.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
        d.addWindowListener(new WindowAdapter() {

            @Override
            public void windowClosing(WindowEvent e) {
                System.exit(0);
            }
        });
        d.setVisible(true);
    }
}

Please note that I did not use setUndecorated(true); to be able to respond to closing the window. If you have other means to respond on such requests, for example by clicking on a button inside the dialog, you can of course use setUndecorated(true);.