java.awt.Window.setAlwaysOnTop()方法的使用及代码示例

x33g5p2x  于2022-02-02 转载在 其他  
字(8.1k)|赞(0)|评价(0)|浏览(247)

本文整理了Java中java.awt.Window.setAlwaysOnTop()方法的一些代码示例,展示了Window.setAlwaysOnTop()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Window.setAlwaysOnTop()方法的具体详情如下:
包路径:java.awt.Window
类名称:Window
方法名:setAlwaysOnTop

Window.setAlwaysOnTop介绍

暂无

代码示例

代码示例来源:origin: stackoverflow.com

import javax.swing.JFrame;
import javax.swing.JLabel;

public class Annoying {
  public static void main(String[] args) {
    JFrame frame = new JFrame("Hello!!");

    // Set's the window to be "always on top"
    frame.setAlwaysOnTop( true );

    frame.setLocationByPlatform( true );
    frame.add( new JLabel("  Isn't this annoying?") );
    frame.pack();
    frame.setVisible( true );
  }
}

代码示例来源:origin: stackoverflow.com

w.setAlwaysOnTop(true);
w.setBounds(w.getGraphicsConfiguration().getBounds());
w.setVisible(true);

代码示例来源:origin: stackoverflow.com

Window w=new Window(null)
{
 @Override
 public void paint(Graphics g)
 {
  final Font font = getFont().deriveFont(48f);
  g.setFont(font);
  g.setColor(Color.RED);
  final String message = "Hello";
  FontMetrics metrics = g.getFontMetrics();
  g.drawString(message,
   (getWidth()-metrics.stringWidth(message))/2,
   (getHeight()-metrics.getHeight())/2);
 }
 @Override
 public void update(Graphics g)
 {
  paint(g);
 }
};
w.setAlwaysOnTop(true);
w.setBounds(w.getGraphicsConfiguration().getBounds());
w.setBackground(new Color(0, true));
w.setVisible(true);

代码示例来源:origin: stackoverflow.com

this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
this.setLocationRelativeTo(owner);
this.setAlwaysOnTop(true);
this.addWindowFocusListener(new WindowFocusListener() {

代码示例来源:origin: stackoverflow.com

DragPanel.class, DataFlavor.javaJVMLocalObjectMimeType, "JLabel");
window.add(label);
window.setAlwaysOnTop(true);
window.setBackground(new Color(0,true));
DragSource.getDefaultDragSource().addDragSourceMotionListener(

代码示例来源:origin: stackoverflow.com

dialog.add(btn1);
dialog.setVisible(false);
dialog.setAlwaysOnTop(true);
dialog.setModal(true);
dialog.setLayout(new GridLayout(2, 0, 10, 10));

代码示例来源:origin: stackoverflow.com

import java.io.File;
import javax.swing.JDialog;
import javax.swing.JFileChooser;
import javax.swing.JFrame;

public class GFileChooserDialog extends JDialog {

  private JFileChooser fileChooser;   
  private File file;

  public GFileChooserDialog(JFrame relativeTo) {
    super(relativeTo, true); 
    this.setAlwaysOnTop(true);
    this.fileChooser = new JFileChooser();
    this.getContentPane().setSize(450, 300);
    int returnVal = fileChooser.showOpenDialog(this);
    if (returnVal == JFileChooser.APPROVE_OPTION) {
      file = fileChooser.getSelectedFile();            
    } 
  }

  public File getFile() {
    return file;
  }
  public void setFile(File file) {
    this.file = file;
  }   
}

代码示例来源:origin: aterai/java-swing-tips

private MainPanel() {
 super(new BorderLayout());
 JCheckBox check = new JCheckBox("Always On Top", true);
 check.addActionListener(e -> {
  JCheckBox c = (JCheckBox) e.getSource();
  Container w = c.getTopLevelAncestor();
  if (w instanceof Window) {
   ((Window) w).setAlwaysOnTop(c.isSelected());
  }
 });
 JPanel p = new JPanel();
 p.add(check);
 p.setBorder(BorderFactory.createTitledBorder("JFrame#setAlwaysOnTop(boolean)"));
 add(p, BorderLayout.NORTH);
 setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
 setPreferredSize(new Dimension(320, 240));
}

代码示例来源:origin: stackoverflow.com

import java.awt.Frame;
import javax.swing.*;

class TestFrameSize {

  public static void main(String[] args) {
    SwingUtilities.invokeLater(new Runnable() {
      public void run() {
        JFrame f = new JFrame("Test Screen Size");
        f.setAlwaysOnTop(true);
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        System.out.println(f.getToolkit().getScreenSize());
        f.setExtendedState(Frame.MAXIMIZED_BOTH);
        f.setVisible(true);
        System.out.println(f.getSize());
      }
    });
  }
}

代码示例来源:origin: stackoverflow.com

import javax.swing.*;

public class AfterJFrameClose {

  public static void main(String[] args) {
    JFrame frame = new JFrame("My frame");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setVisible(true);
    frame.setAlwaysOnTop(true);

    frame.addWindowListener(new java.awt.event.WindowAdapter() {
      @Override
      public void windowClosing(java.awt.event.WindowEvent windowEvent) {
        System.out.println("Frame closing");
      }
    });
  }
}

代码示例来源:origin: stackoverflow.com

import javax.swing.*;
import java.awt.*;
public class test extends JWindow{
  public test(){
    super();
    this.setSize(500, 400);
    this.setLocation(50, 50);

    setBackground(new Color(0,0,0,0)); // this is the critical line - that fourth 0 represents alpha (or opacity)

    setAlwaysOnTop( true );  // keeps it in the foreground so you don't click away from it - note that clicks on the transparent part DO pass through to the desktop, at least on Lion

    JLabel testLabel = new JLabel("Floating text hah");
    this.add(testLabel);

  }
  public static void main(String[] args){
    System.out.println("Sup");
    test t = new test();
    t.setVisible(true);
  }
}

代码示例来源:origin: stackoverflow.com

frame1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame1.setVisible(true);
frame1.setAlwaysOnTop(true);
JFrame frame2 = new JFrame("Second frame");
frame2.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame2.setVisible(true);
frame2.setAlwaysOnTop(true);
showFrameOnScreen(frame1, 1);
showFrameOnScreen(frame2, 2);

代码示例来源:origin: stackoverflow.com

import javax.swing.JDesktopPane;
import javax.swing.JFrame;
import javax.swing.JInternalFrame;
import net.miginfocom.swing.MigLayout;

public class MainClass {

  public static void main(String[] args) {
    JFrame frame = new JFrame ();
    frame.setVisible(true);
    frame.setAlwaysOnTop(true);
    final JDesktopPane desktopPane = new JDesktopPane();
    desktopPane.setLayout(new MigLayout("center panel",
        "[100px:100px:1366px,grow,shrink 50,center]",
        "[100px:100px:768px,grow,shrink 50,center]"));
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);        
    JInternalFrame form = new JInternalFrame();
    form.setResizable(true);      
    form.setVisible(true);
    desktopPane.add(form);
    frame.add(desktopPane);
  }
}

代码示例来源:origin: tulskiy/musique

private void showJPopupMenu(MouseEvent e) {
  try {
    if (e.isPopupTrigger() && menu != null) {
      if (window == null) {
        if (isWindows) {
          window = new JDialog((Frame) null);
          ((JDialog) window).setUndecorated(true);
        } else {
          window = new JWindow((Frame) null);
        }
        window.setAlwaysOnTop(true);
        Dimension size = menu.getPreferredSize();
        Point centerPoint = GraphicsEnvironment.getLocalGraphicsEnvironment().getCenterPoint();
        if (e.getY() > centerPoint.getY())
          window.setLocation(e.getX(), e.getY() - size.height);
        else
          window.setLocation(e.getX(), e.getY());
        window.setVisible(true);
        menu.show(((RootPaneContainer) window).getContentPane(), 0, 0);
        // popup works only for focused windows
        window.toFront();
      }
    }
  } catch (Exception ignored) {
  }
}

代码示例来源:origin: stackoverflow.com

import java.awt.Dimension;
  import javax.swing.*;

  public class testDialog
 {

public static void main(String []args)
  {
   JDialog d=new JDialog();
  JInternalFrame i=new JInternalFrame("HI",false,false,false,false);
  i.setPreferredSize(new Dimension(100,100));
  d.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
   d.setTitle("Wait dialog");
  d.add(i);
  d.pack();
  d.setPreferredSize(new Dimension(100,100));
  d.setLocation(300,300);
   d.setAlwaysOnTop(true);
  d.setVisible(true);
   }
   }

代码示例来源:origin: stackoverflow.com

frame.setAlwaysOnTop(true);

代码示例来源:origin: nz.ac.waikato.cms.weka/weka-stable

/**
 * Called by the KnowledgeFlow application once the enclosing JFrame is
 * visible
 */
@Override
public void nowVisible() {
 m_parent.setSize(600, 180);
 ((JFrame) m_parent).setResizable(false);
 m_parent.setAlwaysOnTop(true);
 m_parent.validate();
 int iwidth = m_plotPanel.getWidth();
 int iheight = m_plotPanel.getHeight();
 m_osi = m_plotPanel.createImage(iwidth, iheight);
 Graphics m = m_osi.getGraphics();
 m.setColor(m_BackgroundColor);
 m.fillRect(0, 0, iwidth, iheight);
 m_previousY[0] = -1;
 setRefreshWidth();
}

代码示例来源:origin: Waikato/weka-trunk

/**
 * Called by the KnowledgeFlow application once the enclosing JFrame is
 * visible
 */
@Override
public void nowVisible() {
 m_parent.setSize(600, 180);
 ((JFrame) m_parent).setResizable(false);
 m_parent.setAlwaysOnTop(true);
 m_parent.validate();
 int iwidth = m_plotPanel.getWidth();
 int iheight = m_plotPanel.getHeight();
 m_osi = m_plotPanel.createImage(iwidth, iheight);
 Graphics m = m_osi.getGraphics();
 m.setColor(m_BackgroundColor);
 m.fillRect(0, 0, iwidth, iheight);
 m_previousY[0] = -1;
 setRefreshWidth();
}

代码示例来源:origin: stackoverflow.com

setAlwaysOnTop(true);
setResizable(false);
setMinimumSize(new Dimension(300, 300));

代码示例来源:origin: stackoverflow.com

setUndecorated(true);
setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
setAlwaysOnTop(true);
setOpacity(0.8f);
setSize(200, 200);

相关文章

Window类方法