eclipse SWT 中实现工程图标最小化到托盘,并只能右键托盘图标选择关闭
来源:互联网 发布:拳皇97风云再起mac版 编辑:程序博客网 时间:2024/05/22 08:09
已经好久没有写博客了,前段时间忙着公司实习,做java C/S下的工程,现将开发过程中遇到的难题整理下来,请持续关注!!谢谢!!
好了,话不多说,首先和大家介绍eclipse SWT 中实现工程图标最小化到托盘,并只能右键托盘图标选择关闭的功能。并且运行工程任务栏有图标,但托盘没有,当关闭桌面上的工程时,图标只在托盘显示。部分代码如下:
</pre><pre name="code" class="html"><span style="font-size:14px;">Display display =new Display();</span>
<span style="font-size:14px;">protected Tray tray;protected TrayItem trayItem;protected Menu trayMenu;protected MenuItem showMenuItem,exitMenuItem;</span>
<span style="font-size:14px;"><span style="white-space:pre"></span>//给应用程序指定一个系统图标<span style="white-space:pre"></span>shell.setImage(display.getSystemImage(SWT.ICON_WORKING)); //构造系统栏控件 tray = display.getSystemTray(); trayItem = new TrayItem(tray, SWT.NONE); //程序启动时,窗口是显示的,所以任务栏栏图标隐藏 trayItem.setVisible(false); trayItem.setToolTipText(shell.getText()); trayItem.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { toggleDisplay(shell, tray); } }); trayMenu = new Menu(shell, SWT.POP_UP); showMenuItem = new MenuItem(trayMenu, SWT.PUSH); showMenuItem.setText("显示窗口(&show)"); //显示窗口,并隐藏任务栏</span><span style="font-size:14px;">图标 showMenuItem.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { toggleDisplay(shell, tray); } }); trayMenu.setDefaultItem(showMenuItem); new MenuItem(trayMenu, SWT.SEPARATOR); //托盘中的退出菜单,程序只能通过这个菜单退出 exitMenuItem = new MenuItem(trayMenu, SWT.PUSH); exitMenuItem.setText("退出程序(&exit)"); exitMenuItem.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { int closeserial=JOptionPane.showConfirmDialog(null, "确定退出?","提示:", JOptionPane.YES_NO_OPTION); if(closeserial==0){ shell.dispose(); try {serialread.close();} catch (SerialPortException e) {e.printStackTrace();} } } }); //在托盘图标点击鼠标右键时的事件,弹出菜单 trayItem.addMenuDetectListener(new MenuDetectListener(){ public void menuDetected(MenuDetectEvent e) { trayMenu.setVisible(true); } }); trayItem.setImage(shell.getImage()); shell.addShellListener(new ShellAdapter() { //点击窗口最小化按钮时,窗口隐藏,托盘显示图标 public void shellIconified(ShellEvent e) { toggleDisplay(shell, tray); } //点击窗口关闭按钮时,并不终止程序,而是隐藏窗口,同时托盘显示图标 public void shellClosed(ShellEvent e) { e.doit = false; //消耗掉原本系统来处理的事件 toggleDisplay(shell, tray); } /* public void shellClosed(ShellEvent e) { MessageBox messagebox = new MessageBox(shell, SWT.ICON_QUESTION | SWT.YES | SWT.NO); messagebox.setText("关闭串口设置:"); messagebox.setMessage("您确定要退出吗?") ; int message = messagebox.open(); e.doit = message == SWT.YES; try {serialread.close();} catch (SerialPortException e1) {e1.printStackTrace();} }*/ });</span>
0 0
- eclipse SWT 中实现工程图标最小化到托盘,并只能右键托盘图标选择关闭
- SWT 中实现最小化到托盘图标,并只能通过托盘的弹出菜单关闭程序
- SWT 中实现最小化到托盘图标,并只能通过托盘的弹出菜单关闭程序
- 最小化到托盘并有图标闪烁效果
- 最小化到托盘并有图标闪烁效果
- 在vc中将程序图标最小化到托盘中
- Winform窗体实现最小化托盘图标
- VC++中实现程序启动后隐藏窗口,最小化到托盘图标。
- VC++中实现程序启动后隐藏窗口,最小化到托盘图标。
- 托盘图标及右键菜单
- 实现最小化到托盘
- 如何实现托盘图标
- Air实现托盘图标
- C#实现托盘图标
- mfc实现托盘图标
- C#实现托盘图标
- VC++ 四步实现最小化托盘图标---音乐播放器
- 最小化后右下角(托盘)小图标的实现
- 根据JQuery开发自定义插件。
- PS快速制作流血火焰和冰封字体
- HDU 1273 漫步森林 (纯数学问题)
- UITableView总结
- android-Backing up App Data to the Cloud
- eclipse SWT 中实现工程图标最小化到托盘,并只能右键托盘图标选择关闭
- 删除卸载Homebrew的正确姿势
- 关于高并发之初学一
- Android平台开发之线程和进程的详解
- 华为机试——挑7
- selection算法
- 用sizeof运算符的一个注意事项(一个新人的C++学习记录)
- 中文文本处理简要介绍
- zookeeper集群搭建