swing - Change the icon name in the notification area in windows in Java -
i created program supports system tray notifications. set icon tooltip , balloon message system tray. when start program icon appears in notification area icons in windows , default name next java(tm) platform se binary. can change default name custom name program name?
please caused code too
import java.awt.awtexception; import java.awt.color; import java.awt.component; import java.awt.graphics; import java.awt.graphics2d; import java.awt.graphicsconfiguration; import java.awt.graphicsdevice; import java.awt.graphicsenvironment; import java.awt.image; import java.awt.menuitem; import java.awt.popupmenu; import java.awt.systemtray; import java.awt.trayicon; import java.awt.event.actionevent; import java.awt.event.actionlistener; import java.awt.image.bufferedimage; import java.beans.propertychangeevent; import java.beans.propertychangelistener; import java.util.logging.level; import java.util.logging.logger; import javax.swing.abstractaction; import javax.swing.action; import javax.swing.icon; import javax.swing.imageicon; import javax.swing.swingutilities; import javax.swing.timer; import javax.swing.uimanager; public class activetray { private systemtray tray; private trayicon trayicon; private icon icon, icon1; private image image, image1; private timer timer; public activetray() { if (systemtray.issupported() == false) { system.err.println("no system tray available"); return; } tray = systemtray.getsystemtray(); propertychangelistener proplistener = new propertychangelistener() { public void propertychange(propertychangeevent evt) { trayicon oldtray[] = (trayicon[]) evt.getoldvalue(); trayicon newtray[] = (trayicon[]) evt.getnewvalue(); system.out.println(oldtray.length + " / " + newtray.length); } }; tray.addpropertychangelistener("trayicons", proplistener); icon = new bevelarrowicon(bevelarrowicon.up, false, false); image = icontoimage(icon); icon1 = new bevelarrowicon(bevelarrowicon.down, false, false); image1 = icontoimage(icon1); popupmenu popup = new popupmenu(); menuitem item = new menuitem("hello, world"); trayicon = new trayicon(image, "tip text", popup); actionlistener menuactionlistener = new actionlistener() { public void actionperformed(actionevent e) { trayicon.displaymessage("good-bye", "cruel world", trayicon.messagetype.warning); } }; item.addactionlistener(menuactionlistener); popup.add(item); actionlistener actionlistener = new actionlistener() { public void actionperformed(actionevent e) { tray.remove(trayicon); } }; trayicon.addactionlistener(actionlistener); try { tray.add(trayicon); start(); } catch (awtexception ex) { logger.getlogger(activetray.class.getname()).log(level.severe, null, ex); } } private void start() { timer = new javax.swing.timer(125, updatecol()); timer.start(); trayicon.displaymessage(null, " aplication loaded ", trayicon.messagetype.none); } private action updatecol() { return new abstractaction("icon load action") { private static final long serialversionuid = 1l; @override public void actionperformed(actionevent e) { runnable dorun = new runnable() { @override public void run() { image img = trayicon.getimage(); if (img == image) { trayicon.setimage(image1); } else { trayicon.setimage(image); } } }; swingutilities.invokelater(dorun); } }; } public static void main(string args[]) { activetray activetray = new activetray(); } static image icontoimage(icon icon) { if (icon instanceof imageicon) { return ((imageicon) icon).getimage(); } else { int w = icon.geticonwidth(); int h = icon.geticonheight(); graphicsenvironment ge = graphicsenvironment.getlocalgraphicsenvironment(); graphicsdevice gd = ge.getdefaultscreendevice(); graphicsconfiguration gc = gd.getdefaultconfiguration(); bufferedimage image = gc.createcompatibleimage(w, h); graphics2d g = image.creategraphics(); icon.painticon(null, g, 0, 0); g.dispose(); return image; } } static class bevelarrowicon implements icon { public static final int = 0; // direction public static final int down = 1; private static final int default_size = 16; private color edge1; private color edge2; private color fill; private int size; private int direction; public bevelarrowicon(int direction, boolean israisedview, boolean ispressedview) { if (israisedview) { if (ispressedview) { init(uimanager.getcolor("controllthighlight"), uimanager.getcolor("controldkshadow"), uimanager.getcolor("controlshadow"), default_size, direction); } else { init(uimanager.getcolor("controlhighlight"), uimanager.getcolor("controlshadow"), uimanager.getcolor("control"), default_size, direction); } } else { if (ispressedview) { init(uimanager.getcolor("controldkshadow"), uimanager.getcolor("controllthighlight"), uimanager.getcolor("controlshadow"), default_size, direction); } else { init(uimanager.getcolor("controlshadow"), uimanager.getcolor("controlhighlight"), uimanager.getcolor("control"), default_size, direction); } } } public bevelarrowicon(color edge1, color edge2, color fill, int size, int direction) { init(edge1, edge2, fill, size, direction); } @override public void painticon(component c, graphics g, int x, int y) { switch (direction) { case down: drawdownarrow(g, x, y); break; case up: drawuparrow(g, x, y); break; } } @override public int geticonwidth() { return size; } @override public int geticonheight() { return size; } private void init(color edge1, color edge2, color fill, int size, int direction) { edge1 = color.red; edge2 = color.blue; this.edge1 = edge1; this.edge2 = edge2; this.fill = fill; this.size = size; this.direction = direction; } private void drawdownarrow(graphics g, int xo, int yo) { g.setcolor(edge1); g.drawline(xo, yo, xo + size - 1, yo); g.drawline(xo, yo + 1, xo + size - 3, yo + 1); g.setcolor(edge2); g.drawline(xo + size - 2, yo + 1, xo + size - 1, yo + 1); int x = xo + 1; int y = yo + 2; int dx = size - 6; while (y + 1 < yo + size) { g.setcolor(edge1); g.drawline(x, y, x + 1, y); g.drawline(x, y + 1, x + 1, y + 1); if (0 < dx) { g.setcolor(fill); g.drawline(x + 2, y, x + 1 + dx, y); g.drawline(x + 2, y + 1, x + 1 + dx, y + 1); } g.setcolor(edge2); g.drawline(x + dx + 2, y, x + dx + 3, y); g.drawline(x + dx + 2, y + 1, x + dx + 3, y + 1); x += 1; y += 2; dx -= 2; } g.setcolor(edge1); g.drawline(xo + (size / 2), yo + size - 1, xo + (size / 2), yo + size - 1); } private void drawuparrow(graphics g, int xo, int yo) { g.setcolor(edge1); int x = xo + (size / 2); g.drawline(x, yo, x, yo); x--; int y = yo + 1; int dx = 0; while (y + 3 < yo + size) { g.setcolor(edge1); g.drawline(x, y, x + 1, y); g.drawline(x, y + 1, x + 1, y + 1); if (0 < dx) { g.setcolor(fill); g.drawline(x + 2, y, x + 1 + dx, y); g.drawline(x + 2, y + 1, x + 1 + dx, y + 1); } g.setcolor(edge2); g.drawline(x + dx + 2, y, x + dx + 3, y); g.drawline(x + dx + 2, y + 1, x + dx + 3, y + 1); x -= 1; y += 2; dx += 2; } g.setcolor(edge1); g.drawline(xo, yo + size - 3, xo + 1, yo + size - 3); g.setcolor(edge2); g.drawline(xo + 2, yo + size - 2, xo + size - 1, yo + size - 2); g.drawline(xo, yo + size - 1, xo + size, yo + size - 1); } } }
Comments
Post a Comment