linux - Java app Tray Icon not displaying properly on CentOS -


i've written java app can used on both windows , linux. app uses trayicon. on windows, works perfectly, on linux (centos) trayicon has 2 problems: 1) i've lost transparency in png image) , 2) image looks shifted (more on later).

i take account the different environments getting tray icon size , scaling accordingly. here code:

dimension trayiconsize = tray.gettrayiconsize(); image originalimage = toolkit.getimage("tray_icon.png"); image scaledimage = originalimage.getscaledinstance(trayiconsize.width, trayiconsize.height, image.scale_smooth); trayicon = new trayicon(scaledimage, "some text"); 

on centos, returned dimension .gettrayiconsize() 24x24, after testing, it's fits 24x32 (wxh) image, accounts image appearing shifted when set 24x24.

is there way maintain background transparency? also, suggestions on getting sized icon dynamically?

size

although documentation states systemtray.gettrayiconsize() "returns size, in pixels, of space tray icon occupy in system tray", implementation returns constant value depending on operating system.

this actual implementation of method in xsystemtraypeer.java (oracle jre 1.8, openjdk similar):

public dimension gettrayiconsize() {     return new dimension(24, 24); } 

this not linux restriction. windows specific implementation returns constant dimension of 16x16. while windows systems seem stick size, vast multitude of linux desktops comes equally large variety of system trays in shapes , sizes. method therefore error prone , cannot relied on.

transparency

transparency not supported in x11 implementation of system tray. see this answer , this bug report details.

alternatives

take @ dorkbox/systemtray. it's apache 2.0 licensed tray lib available through maven/gradle. supports dynamic scaling , transparency on platforms , supports appindicator. i'm not affiliated project.


Comments

Popular posts from this blog

PHP DOM loadHTML() method unusual warning -

python - How to create jsonb index using GIN on SQLAlchemy? -

c# - TransactionScope not rolling back although no complete() is called -