Java Code Examples for javax.swing.JWindow#setAlwaysOnTop()

The following examples show how to use javax.swing.JWindow#setAlwaysOnTop() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WindowNotification.java    From JCommunique with MIT License 6 votes vote down vote up
public WindowNotification() {
	m_window = new JWindow();
	m_window.setAlwaysOnTop(true);

	m_listener = new MouseAdapter() {
		@Override
		public void mouseClicked(MouseEvent e) {
			fireListeners(CLICKED);
			if (m_closeOnClick)
				removeFromManager();
		}
	};

	setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);
	setPanel(new JPanel());
}
 
Example 2
Source File: AbstractSliderTool.java    From wandora with GNU General Public License v3.0 5 votes vote down vote up
private void initializeSlider(TopicMapGraphPanel gp) {
    int minValue = getMinValue(gp);
    int maxValue = getMaxValue(gp);
    int defaultValue = getDefaultValue(gp);
    
    if(defaultValue < minValue) defaultValue = minValue;
    if(defaultValue > maxValue) defaultValue = maxValue;

    slider = new SimpleSlider(SimpleSlider.HORIZONTAL, minValue, maxValue, defaultValue);
    sliderLabel = new SimpleLabel();
    sliderPopup = new JWindow();

    slider.setPreferredSize(new Dimension(120, 24));
    slider.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
    
    sliderLabel.setFont(UIConstants.smallButtonLabelFont);
    sliderLabel.setPreferredSize(new Dimension(30, 24));
    sliderLabel.setHorizontalAlignment(SimpleLabel.CENTER);
    
    JPanel panel = new JPanel();
    panel.setBorder(new LineBorder(UIConstants.defaultBorderShadow));
    panel.setLayout(new BorderLayout(2,2));
    panel.add(slider, BorderLayout.CENTER);
    panel.add(sliderLabel, BorderLayout.EAST);

    sliderPopup.setLayout(new BorderLayout(2,2));
    sliderPopup.add(panel, BorderLayout.CENTER);
    sliderPopup.setSize(150, 24);

    // sliderPopup.addMouseListener(this);
    sliderPopup.setAlwaysOnTop(true);
    
    slider.addChangeListener(this);
    slider.addMouseListener(this);
}
 
Example 3
Source File: RoarPanel.java    From Spark with Apache License 2.0 5 votes vote down vote up
/**
 * Creates the WindowGui
 * 
 * @param icon
 * @param head
 * @param body
 * @param posx
 * @param posy
 * @param backgroundcolor
 * @param headerColor
 * @param messageColor
 * @return
 */
private static JWindow createWindow(Icon icon, String head, String body, int posx, int posy, Color backgroundcolor,
        Color headerColor, Color messageColor) {

    final JWindow window = new JWindow();
    JPanel windowpanel = new JPanel(new GridBagLayout());
    windowpanel.setBackground(backgroundcolor);

    AWTUtilities.setWindowShape(window, new RoundRectangle2D.Float(0, 0, WIDTH, HEIGHT, 20, 20));

    try
    {
        AWTUtilities.setWindowOpaque( window, true );
    } catch ( UnsupportedOperationException ex ) {
        Log.debug( "Unable to make window opaque: " + ex );
    }
    JLabel text = new JLabel("<HTML>" + body + "</HTML>");
    text.setForeground(messageColor);

    JLabel header = new JLabel(head);
    header.setForeground(headerColor);
    header.setFont(new Font(header.getFont().getName(), Font.BOLD, header.getFont().getSize() + 2));

    windowpanel.add(new JLabel(icon), new GridBagConstraints(0, 0, 1, 2, 0.0, 0.0, GridBagConstraints.CENTER,
            GridBagConstraints.BOTH, new Insets(5, 5, 5, 5), 0, 0));

    windowpanel.add(header, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER,
            GridBagConstraints.BOTH, new Insets(5, 5, 0, 5), 0, 0));
    windowpanel.add(text, new GridBagConstraints(1, 1, 2, 1, 1.0, 1.0, GridBagConstraints.NORTHWEST,
            GridBagConstraints.HORIZONTAL, new Insets(0, 5, 0, 5), 0, 0));

    window.add(windowpanel);
    window.setSize(WIDTH, HEIGHT);
    window.setLocation(posx - (WIDTH + 5), posy + 5);
    window.setAlwaysOnTop(true);

    return window;
}
 
Example 4
Source File: ProfilerPopup.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public void show() {
//        Component focusOwner = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();
//        if (focusOwner != null) focusRef = new WeakReference(focusOwner);
            
        owner = ownerRef == null ? null : ownerRef.get();
        ownerLocation = owner == null ? null : owner.getLocationOnScreen();
        
        window = new JWindow(owner);
        window.setType(Window.Type.POPUP);
        window.setAlwaysOnTop(false);
        window.setFocusable(true);
        window.setFocusableWindowState(true);
        window.setAutoRequestFocus(true);
        
        window.getContentPane().add(content);
        window.pack();
        
        if (popupAlign == -1) {
            window.setLocation(location.getLocation());
        } else {
            Dimension size = content.getSize();
            
            int x;
            switch (popupAlign) {
                case SwingConstants.EAST:
                case SwingConstants.NORTH_EAST:
                case SwingConstants.SOUTH_EAST:
                    x = location.x + location.width - size.width + 1;
                    break;
                default:
                    x = location.x + 1;
                    break;
            }
            
            int y;
            switch (popupAlign) {
                case SwingConstants.NORTH:
                case SwingConstants.NORTH_EAST:
                case SwingConstants.NORTH_WEST:
                    y = location.y - size.height + 1;
                    break;
                default:
                    y = location.y + location.height + 1;
                    break;
            }
            
            window.setLocation(x, y);
        }
        
        window.setVisible(true);
        
        Component defaultFocus = content.getFocusTraversalPolicy().getDefaultComponent(content);
        if (defaultFocus != null) defaultFocus.requestFocusInWindow();
        
        content.installListeners();
        
        if (listener != null) listener.popupShown();
    }
 
Example 5
Source File: ProfilerPopup.java    From visualvm with GNU General Public License v2.0 4 votes vote down vote up
public void show() {
//        Component focusOwner = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();
//        if (focusOwner != null) focusRef = new WeakReference(focusOwner);
            
        owner = ownerRef == null ? null : ownerRef.get();
        ownerLocation = owner == null ? null : owner.getLocationOnScreen();
        
        window = new JWindow(owner);
        window.setType(Window.Type.POPUP);
        window.setAlwaysOnTop(false);
        window.setFocusable(true);
        window.setFocusableWindowState(true);
        window.setAutoRequestFocus(true);
        
        window.getContentPane().add(content);
        window.pack();
        
        if (popupAlign == -1) {
            window.setLocation(location.getLocation());
        } else {
            Dimension size = content.getSize();
            
            int x;
            switch (popupAlign) {
                case SwingConstants.EAST:
                case SwingConstants.NORTH_EAST:
                case SwingConstants.SOUTH_EAST:
                    x = location.x + location.width - size.width + 1;
                    break;
                default:
                    x = location.x + 1;
                    break;
            }
            
            int y;
            switch (popupAlign) {
                case SwingConstants.NORTH:
                case SwingConstants.NORTH_EAST:
                case SwingConstants.NORTH_WEST:
                    y = location.y - size.height + 1;
                    break;
                default:
                    y = location.y + location.height + 1;
                    break;
            }
            
            window.setLocation(x, y);
        }
        
        window.setVisible(true);
        
        Component defaultFocus = content.getFocusTraversalPolicy().getDefaultComponent(content);
        if (defaultFocus != null) defaultFocus.requestFocusInWindow();
        
        content.installListeners();
        
        if (listener != null) listener.popupShown();
    }
 
Example 6
Source File: QPopup.java    From pumpernickel with MIT License 4 votes vote down vote up
/**
 * 
 * @param screenLoc
 * @param calloutType
 * @param forceShow
 *            if true then this method will always return true and try to
 *            show a window. If false then this method may decide to return
 *            false and not show the popup. For example: if the popup would
 *            fall far outside the window, this may return false in hopes
 *            that another attempt will get better coverage.
 * @return
 */
private boolean showUsingWindow(Point screenLoc, CalloutType calloutType,
		boolean forceShow) {
	Point windowLoc = new Point(screenLoc);
	if (calloutType == null) {
		ui.setCalloutType(CalloutType.TOP_CENTER);
		ui.setCalloutSize(0);
	} else {
		ui.setCalloutType(calloutType);
		ui.setCalloutSize(CALLOUT_SIZE);
	}

	contents.validate();
	contents.setSize(contents.getPreferredSize());

	if (calloutType != null) {
		Point calloutTip = ui.getCalloutTip(contents);
		windowLoc.x -= calloutTip.x;
		windowLoc.y -= calloutTip.y;
	}

	Rectangle windowBounds = new Rectangle(windowLoc, contents.getSize());

	if (!forceShow && !isScreenRectVisible(windowBounds))
		return false;

	// closing and creating new windows to constantly reposition causes
	// flickering; we should reuse the existing window if we're already
	// visible.
	JWindow window = null;
	if (contents.getParent() != null) {
		Window w = SwingUtilities.getWindowAncestor(contents);
		if (w instanceof JWindow) {
			JWindow jw = (JWindow) w;
			Boolean b = (Boolean) jw.getRootPane()
					.getClientProperty(PROPERTY_IS_QPOPUP);
			if (Boolean.TRUE.equals(b)) {
				window = jw;
			}
		}

		if (window == null) {
			hide();
		}
	}
	if (window == null) {
		window = createWindow();
	}

	if (isToolTip())
		window.setFocusable(false);
	window.setBounds(windowBounds);
	window.setVisible(true);
	window.setAlwaysOnTop(true);
	window.toFront();
	return true;
}
 
Example 7
Source File: MainFrame.java    From netbeans-mmd-plugin with Apache License 2.0 4 votes vote down vote up
private void menuFullScreenActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuFullScreenActionPerformed

    final AbstractEditor selectedEditor = this.tabPane.getCurrentEditor();
    if (selectedEditor != null) {
      final GraphicsConfiguration gconfig = this.getGraphicsConfiguration();
      if (gconfig != null) {
        final GraphicsDevice device = gconfig.getDevice();
        if (device.isFullScreenSupported()) {
          if (device.getFullScreenWindow() == null) {
            final JLabel label = new JLabel("Opened in full screen");
            final int tabIndex = this.tabPane.getSelectedIndex();
            this.tabPane.setComponentAt(tabIndex, label);
            final JWindow window = new JWindow(Main.getApplicationFrame());
            window.setAlwaysOnTop(true);
            window.setAutoRequestFocus(true);
            window.setContentPane(selectedEditor.getContainerToShow());

            endFullScreenIfActive();

            final KeyEventDispatcher fullScreenEscCatcher = (@Nonnull final KeyEvent e) -> {
              if (e.getID() == KeyEvent.KEY_PRESSED && (e.getKeyCode() == KeyEvent.VK_ESCAPE || e.getKeyCode() == KeyEvent.VK_F11)) {
                endFullScreenIfActive();
                return true;
              }
              return false;
            };

            if (this.taskToEndFullScreen.compareAndSet(null, (Runnable) () -> {
              try {
                window.dispose();
              } finally {
                tabPane.setComponentAt(tabIndex, selectedEditor.getContainerToShow());
                device.setFullScreenWindow(null);
                KeyboardFocusManager.getCurrentKeyboardFocusManager().removeKeyEventDispatcher(fullScreenEscCatcher);
              }
            })) {
              try {
                KeyboardFocusManager.getCurrentKeyboardFocusManager().addKeyEventDispatcher(fullScreenEscCatcher);
                device.setFullScreenWindow(window);
              } catch (Exception ex) {
                LOGGER.error("Can't turn on full screen", ex); //NOI18N
                endFullScreenIfActive();
                KeyboardFocusManager.getCurrentKeyboardFocusManager().removeKeyEventDispatcher(fullScreenEscCatcher);
              }
            } else {
              LOGGER.error("Unexpected state, processor is not null!"); //NOI18N
            }
          } else {
            LOGGER.warn("Attempt to full screen device which already in full screen!"); //NOI18N
          }
        } else {
          LOGGER.warn("Device doesn's support full screen"); //NOI18N
          DialogProviderManager.getInstance().getDialogProvider().msgWarn(this, "The Device doesn't support full-screen mode!");
        }
      } else {
        LOGGER.warn("Can't find graphics config for the frame"); //NOI18N
      }
    }
  }