Ejemplo n.º 1
0
  public Rectangle getScreenViewableBounds(GraphicsDevice gd) {

    Rectangle bounds = new Rectangle(0, 0, 0, 0);

    if (gd != null) {
      GraphicsConfiguration gc = gd.getDefaultConfiguration();
      bounds = gc.getBounds();
      Insets insets = Toolkit.getDefaultToolkit().getScreenInsets(gc);

      bounds.x += insets.left;
      bounds.y += insets.top;
      bounds.width -= (insets.left + insets.right);
      bounds.height -= (insets.top + insets.bottom);
    }
    return bounds;
  }
Ejemplo n.º 2
0
  private void setTrayIcon(Stage primaryStage)
      throws ClassNotFoundException, UnsupportedLookAndFeelException, InstantiationException,
          IllegalAccessException {

    if (!SystemTray.isSupported()) {
      return;
    }

    SystemTray sTray = SystemTray.getSystemTray();
    primaryStage.setOnCloseRequest(arg0 -> primaryStage.hide());
    JPopupMenu popup = buildSystemTrayJPopupMenu(primaryStage);
    URL url = System.class.getResource("/logo-invert_small.png");
    Image img = Toolkit.getDefaultToolkit().getImage(url);
    TrayIcon icon = new TrayIcon(img, "Qabel");

    icon.setImageAutoSize(true);
    trayIconListener(popup, icon);

    try {
      sTray.add(icon);
    } catch (AWTException e) {
      logger.error("failed to add tray icon: " + e.getMessage(), e);
    }
  }