Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.File;
- public class SomeShell extends Shell {
- private Text text;
- /**
- * Launch the application.
- * @param args
- */
- public static void main(String args[]) {
- try {
- Display display = Display.getDefault();
- SomeShell shell = new SomeShell(display);
- shell.open();
- shell.layout();
- while (!shell.isDisposed()) {
- if (!display.readAndDispatch()) {
- display.sleep();
- }
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- /**
- * Create the shell.
- * @param display
- */
- public SomeShell(Display display) {
- super(display, SWT.SHELL_TRIM);
- text = new Text(this, SWT.BORDER);
- text.setBounds(83, 37, 75, 27);
- Label lblNewLabel = new Label(this, SWT.NONE);
- lblNewLabel.setBounds(10, 37, 68, 17);
- lblNewLabel.setText("New Label");
- createContents();
- try {
- setDiplayIcons(this);
- } catch (FileNotFoundException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- /**
- * Create contents of the shell.
- */
- protected void createContents() {
- setText("SWT Application");
- setSize(450, 300);
- }
- @Override
- protected void checkSubclass() {
- // Disable the check that prevents subclassing of SWT components
- }
- protected void setDiplayIcons(Shell shell) throws FileNotFoundException{
- Display display = shell.getDisplay();
- InputStream inputImgTray = new FileInputStream(new File("icon.png"));
- Image image = new Image(display, inputImgTray);
- shell.setImage(image);
- Tray tray = display.getSystemTray();
- final ToolTip tip = new ToolTip(shell, SWT.BALLOON | SWT.ICON_INFORMATION);
- tip.setMessage("Balloon Message Goes Here!");
- if(tray != null) {
- TrayItem trayItem = new TrayItem(tray, SWT.NONE);
- trayItem.setImage(image);
- tip.setText("Balloon Title goes here.");
- trayItem.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);
- }
- });
- trayItem.addListener (SWT.MenuDetect, new Listener () {
- public void handleEvent (Event event) {
- menu.setVisible (true);
- }
- });
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment