일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 | 31 |
- 그녀가말했다
- 페이스북
- 민동현
- 위피
- itmusic
- 자바
- Java
- brew
- 퀄컴
- 공정위
- 모던음악만만세
- 사요
- HSDPA
- ETF
- 김장훈
- Wibro
- 한국의 기획자들
- 라디오
- 민동현의토요명화
- 차트쇼쇼쇼
- SWT
- "명탐정 코난"
- 러시아
- EV-DO Rev. B
- 김장훈의who
- CDMA
- 유희열의라디오천국
- USIM
- VoIP
- 이지형
- Today
- Total
zyint's blog
System Tray Icon 본문
Many operating systems have the concept of a 'system tray', and it's often nice to be able to ofter a 'tray icon' feature for your application. SWT ships with tray icon support in the form of the org.eclipse.swt.widgets.TrayIcon
class.
Using a tray icon is fairly simple in SWT:
image = new Image(display,
BalloonExample.class.getResourceAsStream("tray_icon.gif")); // ... Tray tray = display.getSystemTray(); if(tray != null) { TrayItem trayItem = new TrayItem(tray, SWT.NONE); trayItem.setImage(image); }
The null check is required simply because not all platforms have a tray, and as such it's an optional feature.
Here is a screenshot of the tray icon on my Ubuntu Linux installation
Most tray items have some kind of menu associated with them. Adding a menu is also quite straightforward.
Tray tray = display.getSystemTray(); if(tray != null) { TrayItem item = new TrayItem(tray, SWT.NONE); item.setImage(image);final Menu menu = new Menu(shell, SWT.POP_UP); MenuItem menuItem = new MenuItem(menu, SWT.PUSH); menuItem.setText("Button A"); menuItem = new MenuItem(menu, SWT.PUSH); menuItem.setText("Button B"); menuItem = new MenuItem(menu, SWT.PUSH); menuItem.setText("Show Tooltip"); item.addListener (SWT.MenuDetect, new Listener () { public void handleEvent (Event event) { menu.setVisible (true); } }); }
Recent releases of SWT (post-M5) finally support balloons/tooltips through the tray icon. Balloons are quite common in platforms with tray icons, so this is a nice feature to finally have. To add a tooltip, simply use the TrayItem.setToolTip(ToolTip)
method, and set the visibility of the tooltip to true when you want to show it.
final ToolTip tip = new ToolTip(shell, SWT.BALLOON | SWT.ICON_INFORMATION); tip.setMessage("Balloon Message Goes Here!"); Tray tray = display.getSystemTray(); if (tray != null) { TrayItem item = new TrayItem(tray, SWT.NONE); item.setImage(image); tip.setText("Balloon Title goes here."); item.setToolTip(tip); final Menu menu = new Menu(shell, SWT.POP_UP); MenuItem menuItem = new MenuItem(menu, SWT.PUSH); menuItem.setText("Button A"); menuItem = new MenuItem(menu, SWT.PUSH); menuItem.setText("Button B"); menuItem = new MenuItem(menu, SWT.PUSH); menuItem.setText("Show Tooltip"); // Add tooltip visibility to menu item. menuItem.addListener (SWT.Selection, new Listener () { public void handleEvent (Event e) { tip.setVisible(true); } }); // Add menu detection listener to tray icon. item.addListener (SWT.MenuDetect, new Listener () { public void handleEvent (Event event) { menu.setVisible (true); } }); }
One of the suggestions made in the SWT snippets is to still show the tooltip even if tray support isn't available (typically, tooltips are triggered by some application behavior). To do this, the tooltip has to be placed manually, rather than as a relative of the tray icon.
final ToolTip tip = new ToolTip(shell, SWT.BALLOON | SWT.ICON_INFORMATION); tip.setMessage("Balloon Message Goes Here!"); tip.setText("Balloon Title goes here."); Tray tray = display.getSystemTray(); if (tray != null) { TrayItem item = new TrayItem(tray, SWT.NONE); item.setImage(image); item.setToolTip(tip); final Menu menu = new Menu(shell, SWT.POP_UP); MenuItem menuItem = new MenuItem(menu, SWT.PUSH); menuItem.setText("Button A"); menuItem = new MenuItem(menu, SWT.PUSH); menuItem.setText("Button B"); menuItem = new MenuItem(menu, SWT.PUSH); menuItem.setText("Show Tooltip"); menuItem.addListener (SWT.Selection, new Listener () { public void handleEvent (Event e) { tip.setVisible(true); } }); item.addListener (SWT.MenuDetect, new Listener () { public void handleEvent (Event event) { menu.setVisible (true); } }); } else { // Set the tooltip location manually. tip.setLocation(100, 100); }
출처 : http://www.eclipsezone.com/eclipse/forums/t66093.rhtml