Hi, I am creating an application for remainder. and I want it to be run in background and monitor all its tasks.
I need help about how to make a java application to be run in background. It should work in linux as well as in windows.

Help me....!

Dani AI

Generated

Following ’s SystemTray suggestion: build the app as a background scheduler and expose only a tray icon (add a popup menu with Open/Exit). Check SystemTray.isSupported() before adding an icon — SystemTray/TrayIcon are the Java API for a cross-platform notification area, but the desktop may still not show legacy tray icons on some Linux setups. Use the tray to re-open the main window and keep the main JFrame hidden while the app runs in the background. (docs.oracle.com)

A minimal pattern (run UI work on the EDT): create a TrayIcon, add listeners that call frame.setVisible(true) / frame.toFront() on double-click, and on minimize or close call frame.setVisible(false) so the app stays in the tray. Example:

if (SystemTray.isSupported()) {
    SystemTray tray = SystemTray.getSystemTray();
    Image img = Toolkit.getDefaultToolkit().getImage("icon.png");
    PopupMenu menu = new PopupMenu();
    MenuItem open = new MenuItem("Open");
    open.addActionListener(e -> SwingUtilities.invokeLater(() -> { frame.setVisible(true); frame.setState(Frame.NORMAL); }));
    menu.add(open);
    menu.add(new MenuItem("Exit")).addActionListener(e -> System.exit(0));
    TrayIcon ti = new TrayIcon(img, "Reminder", menu);
    ti.setImageAutoSize(true);
    tray.add(ti);
    frame.setVisible(false); // start hidden / minimized to tray
}

Use DO_NOTHING_ON_CLOSE and intercept window events so the app doesn’t exit when the window is closed.

If the requirement is “a visible window but no taskbar button,” that is platform-dependent. Use JWindow or a non-modal JDialog (these normally do not create a taskbar entry) or set the window type to UTILITY/POPUP where supported. Some platforms ignore these hints. For a true Windows-only solution you must call native APIs (change extended window styles like WS_EX_TOOLWINDOW / WS_EX_APPWINDOW), typically via JNA or JNI — that is not portable. (docs.oracle.com)

Troubleshooting: verify SystemTray.isSupported(), ensure the icon is small and setImageAutoSize(true), and test on each target desktop (GNOME/KDE/Windows). If a tray icon is unavailable on a given Linux desktop, provide a fallback (start-on-login or a background/systemd --user unit) so the reminders still run.

Recommended Answers

All 6 Replies

Do you mean that it should not have any visible windows? In that case, just don't create any. Any Java app will run in Windows and in Linux unless you go outside strict Java and access an OS-dependent library directly.

yes, but i want that a tray icon should be there on task bar and it should not have any box on task bar after minimize. And also the case may be some times the window may be visible but nothing will be displayed in task bar as if we open any application its box is there on task bar...

Reply...

yes, but i want that a tray icon should be there on task bar and it should not have any box on task bar after minimize. And also the case may be some times the window may be visible but nothing will be displayed in task bar as if we open any application its box is there on task bar...

Reply...

Sorry, I don't know any cross-platform solution for hiding the task bar button. Maybe someone else can help...

Hi, I am creating an application for remainder. and I want it to be run in background and monitor all its tasks.
I need help about how to make a java application to be run in background. It should work in linux as well as in windows.

Help me....!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.