Example usage for javax.swing JFrame setAlwaysOnTop

List of usage examples for javax.swing JFrame setAlwaysOnTop

Introduction

In this page you can find the example usage for javax.swing JFrame setAlwaysOnTop.

Prototype

public final void setAlwaysOnTop(boolean alwaysOnTop) throws SecurityException 

Source Link

Document

Sets whether this window should always be above other windows.

Usage

From source file:Main.java

public static void main(String[] args) {
    JFrame frame = new JFrame("Hello!!");
    frame.setAlwaysOnTop(true);
    frame.setLocationByPlatform(true);//from   w  ww. j a v a  2 s  . co  m
    frame.add(new JLabel("  Always visible"));
    frame.pack();
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JButton button = new JButton("Button");
    frame.add(button);// w w w  .  jav  a 2  s .  co  m

    frame.setAlwaysOnTop(true);
    frame.setSize(500, 500);
    frame.setLocation(500, 500);

    button.addActionListener(e -> {
        JOptionPane optionPane = new JOptionPane("Option Pane");
        optionPane.showMessageDialog(frame, "Message!");
    });

    frame.setVisible(true);
}

From source file:com.ethercamp.harmony.desktop.HarmonyDesktop.java

private void showErrorWindow(String title, String body) {
    try {//  w  w  w  . j  a  v  a  2  s .  c o m
        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        //            System.setProperty("apple.awt.UIElement", "false");

        JPanel panel = new JPanel();
        panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));

        JTextArea textArea = new JTextArea(body);
        JScrollPane scrollPane = new JScrollPane(textArea);
        textArea.setLineWrap(true);
        textArea.setFont(Font.getFont(Font.MONOSPACED));
        textArea.setEditable(false);
        textArea.setWrapStyleWord(true);
        scrollPane.setPreferredSize(new Dimension(500, 500));

        JTextPane titleLabel = new JTextPane();
        titleLabel.setContentType("text/html"); // let the text pane know this is what you want
        titleLabel.setText("<html>" + "<b>" + title + "</b>" + "</html>"); // showing off
        titleLabel.setEditable(false);
        titleLabel.setBackground(null);
        titleLabel.setBorder(null);

        panel.add(titleLabel);
        panel.add(scrollPane);

        final JFrame frame = new JFrame();
        frame.setAlwaysOnTop(true);
        moveCenter(frame);
        frame.setVisible(true);

        JOptionPane.showMessageDialog(frame, panel, "Oops. Ethereum Harmony stopped with error.",
                JOptionPane.CLOSED_OPTION);
        System.exit(1);
    } catch (Exception e) {
        log.error("Problem showing error window", e);
    }
}

From source file:Estructura.Dibujar.java

public void dibujarGrafo(Grafo grafo) {
    for (int i = 0; i < grafo.getVertices().size(); i++) {
        Estrella e = (Estrella) grafo.getVertices().get(i).getValor();
        dibujo.addVertex(e.toString());/*w w  w  .  j a  va  2 s  .c o m*/
    }
    for (int i = 0; i < grafo.getAristas().size(); i++) {
        Arista a = (Arista) grafo.getAristas().get(i).getValor();
        dibujo.addEdge(a.getPesoString(), a.getPuntoA().toString(), a.getPuntoB().toString());
    }

    VisualizationViewer<String, String> vv = new VisualizationViewer<String, String>(
            new CircleLayout<String, String>(dibujo), new Dimension(800, 600));

    //Agrega el peso al label de la arista.
    vv.getRenderContext().setEdgeLabelTransformer(new Transformer<String, String>() {
        @Override
        public String transform(String arg0) {
            return arg0;
        }
    });
    //Agrega el id al label del vertice.
    vv.getRenderContext().setVertexLabelTransformer(new Transformer<String, String>() {
        @Override
        public String transform(String arg0) {
            return arg0;
        }
    });

    JFrame ventanaGrafo = new JFrame();

    ventanaGrafo.getContentPane().add(vv);
    ventanaGrafo.pack();

    ventanaGrafo.pack();
    ventanaGrafo.setAlwaysOnTop(false);
    ventanaGrafo.setVisible(true);
}

From source file:Estructura.Dibujar.java

public void dibujarCamino(Grafo grafo) {
    for (int i = 0; i < grafo.getVertices().size(); i++) {
        Estrella e = (Estrella) grafo.getVertices().get(i).getValor();
        dibujo.addVertex(e.toString());/* w  w  w  . java2  s .c  om*/
    }
    for (int i = 0; i < grafo.getAristas().size(); i++) {
        Arista a = (Arista) grafo.getAristas().get(i).getValor();
        dibujo.addEdge(a.getPesoString(), a.getPuntoA().toString(), a.getPuntoB().toString());
    }

    VisualizationViewer<String, String> vv = new VisualizationViewer<String, String>(
            new CircleLayout<String, String>(dibujo), new Dimension(800, 600));

    //Agrega el peso al label de la arista.
    vv.getRenderContext().setEdgeLabelTransformer(new Transformer<String, String>() {
        @Override
        public String transform(String arg0) {
            return arg0;
        }
    });
    //Agrega el id al label del vertice.
    vv.getRenderContext().setVertexLabelTransformer(new Transformer<String, String>() {
        @Override
        public String transform(String arg0) {
            return arg0;
        }
    });

    Transformer<String, Paint> edgePaint = new Transformer<String, Paint>() {
        public Paint transform(String s) {
            Color color = null;
            for (int i = 0; i < grafo.getAristas().size(); i++) {
                if (s.equals(((Arista) grafo.getAristas().get(i).getValor()).getPesoString())) {
                    color = ((Arista) grafo.getAristas().get(i).getValor()).getColor();
                }

            }
            return color;
        }
    };
    vv.getRenderContext().setEdgeDrawPaintTransformer(edgePaint);

    JFrame ventanaGrafo = new JFrame();
    ventanaGrafo.getContentPane().add(vv);
    ventanaGrafo.pack();

    ventanaGrafo.pack();
    ventanaGrafo.setAlwaysOnTop(false);
    ventanaGrafo.setVisible(true);

}

From source file:at.gv.egiz.bku.local.stal.LocalIdentityLinkSTALFactory.java

@Override
public STAL createSTAL() {
    final LocalBKUWorker stal;
    //http://java.sun.com/docs/books/tutorial/uiswing/misc/focus.html
    // use undecorated JFrame instead of JWindow,
    // which creates an invisible owning frame and therefore cannot getFocusInWindow()
    JFrame dialog = new JFrame("Brgerkarte");
    log.debug("AlwaysOnTop supported: {}.", dialog.isAlwaysOnTopSupported());
    // [#439] make mocca dialog alwaysOnTop
    dialog.setAlwaysOnTop(true);
    dialog.setIconImages(BKUIcons.icons);
    //       dialog.setUndecorated(true);
    //       dialog.getRootPane().setWindowDecorationStyle(JRootPane.NONE);

    if (locale != null) {
        dialog.setLocale(locale);//from  w  ww .j  a v  a 2  s .  c  o m
    }
    LocalHelpListener helpListener = null;
    if (helpURL != null) {
        helpListener = new LocalHelpListener(helpURL, locale);
    } else {
        log.warn("No HELP URL configured, help system disabled.");
    }
    IdentityLinkGUIFacade gui = new IdentityLinkGUI(dialog.getContentPane(), dialog.getLocale(), null,
            new ResourceFontLoader(), helpListener);
    BKUGUIFacade proxy = (BKUGUIFacade) GUIProxy.newInstance(gui, dialog,
            new Class[] { IdentityLinkGUIFacade.class });
    stal = new LocalBKUWorker(proxy, dialog);
    dialog.setPreferredSize(PREFERRED_SIZE);
    dialog.pack();
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    Dimension frameSize = dialog.getSize();
    if (frameSize.height > screenSize.height) {
        frameSize.height = screenSize.height;
    }
    if (frameSize.width > screenSize.width) {
        frameSize.width = screenSize.width;
    }
    dialog.setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2);
    return stal;
}

From source file:at.gv.egiz.bku.local.stal.LocalGetCertificateSTALFactory.java

@Override
public STAL createSTAL() {
    final LocalBKUWorker stal;
    //http://java.sun.com/docs/books/tutorial/uiswing/misc/focus.html
    // use undecorated JFrame instead of JWindow,
    // which creates an invisible owning frame and therefore cannot getFocusInWindow()
    JFrame dialog = new JFrame("Brgerkarte");
    log.debug("AlwaysOnTop supported: {}.", dialog.isAlwaysOnTopSupported());
    // [#439] make mocca dialog alwaysOnTop
    dialog.setAlwaysOnTop(true);
    dialog.setIconImages(BKUIcons.icons);
    //       dialog.setUndecorated(true);
    //       dialog.getRootPane().setWindowDecorationStyle(JRootPane.NONE);

    if (locale != null) {
        dialog.setLocale(locale);/*from  ww  w.  ja  va  2s .  c  om*/
    }
    LocalHelpListener helpListener = null;
    if (helpURL != null) {
        helpListener = new LocalHelpListener(helpURL, locale);
    } else {
        log.warn("No HELP URL configured, help system disabled.");
    }
    GetCertificateGUIFacade gui = new GetCertificateGUI(dialog.getContentPane(), dialog.getLocale(), null,
            new ResourceFontLoader(), helpListener);
    BKUGUIFacade proxy = (BKUGUIFacade) GUIProxy.newInstance(gui, dialog,
            new Class[] { GetCertificateGUIFacade.class, });
    stal = new LocalBKUWorker(proxy, dialog);
    dialog.setPreferredSize(PREFERRED_SIZE);
    dialog.pack();
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    Dimension frameSize = dialog.getSize();
    if (frameSize.height > screenSize.height) {
        frameSize.height = screenSize.height;
    }
    if (frameSize.width > screenSize.width) {
        frameSize.width = screenSize.width;
    }
    dialog.setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2);

    return stal;
}

From source file:at.gv.egiz.bku.local.stal.LocalGetHardwareInfoSTALFactory.java

@Override
public STAL createSTAL() {
    final LocalBKUWorker stal;
    //http://java.sun.com/docs/books/tutorial/uiswing/misc/focus.html
    // use undecorated JFrame instead of JWindow,
    // which creates an invisible owning frame and therefore cannot getFocusInWindow()
    JFrame dialog = new JFrame("Brgerkarte");
    log.debug("AlwaysOnTop supported: {}.", dialog.isAlwaysOnTopSupported());
    // [#439] make mocca dialog alwaysOnTop
    dialog.setAlwaysOnTop(true);
    dialog.setIconImages(BKUIcons.icons);
    //       dialog.setUndecorated(true);
    //       dialog.getRootPane().setWindowDecorationStyle(JRootPane.NONE);

    if (locale != null) {
        dialog.setLocale(locale);//www  .  ja  va 2s  .co  m
    }
    LocalHelpListener helpListener = null;
    if (helpURL != null) {
        helpListener = new LocalHelpListener(helpURL, locale);
    } else {
        log.warn("No HELP URL configured, help system disabled.");
    }
    GetHardwareInfoGUIFacade gui = new GetHardwareInfoGUI(dialog.getContentPane(), dialog.getLocale(), null,
            new ResourceFontLoader(), helpListener);
    BKUGUIFacade proxy = (BKUGUIFacade) GUIProxy.newInstance(gui, dialog,
            new Class[] { GetHardwareInfoGUIFacade.class, });
    stal = new LocalBKUWorker(proxy, dialog);
    dialog.setPreferredSize(PREFERRED_SIZE);
    dialog.pack();
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    Dimension frameSize = dialog.getSize();
    if (frameSize.height > screenSize.height) {
        frameSize.height = screenSize.height;
    }
    if (frameSize.width > screenSize.width) {
        frameSize.width = screenSize.width;
    }
    dialog.setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2);

    return stal;
}

From source file:at.gv.egiz.bku.local.stal.LocalSTALFactory.java

@Override
public STAL createSTAL() {

    final LocalBKUWorker stal;
    //http://java.sun.com/docs/books/tutorial/uiswing/misc/focus.html
    // use undecorated JFrame instead of JWindow,
    // which creates an invisible owning frame and therefore cannot getFocusInWindow()
    JFrame dialog = new JFrame("Brgerkarte");
    log.debug("AlwaysOnTop supported: {}.", dialog.isAlwaysOnTopSupported());
    // [#439] make mocca dialog alwaysOnTop
    dialog.setAlwaysOnTop(true);
    dialog.setIconImages(BKUIcons.icons);
    //    dialog.setUndecorated(true);
    //    dialog.getRootPane().setWindowDecorationStyle(JRootPane.NONE);

    if (locale != null) {
        dialog.setLocale(locale);//www .  j a  v a 2 s  .  c  o m
    }
    LocalHelpListener helpListener = null;
    if (helpURL != null) {
        helpListener = new LocalHelpListener(helpURL, locale);
    } else {
        log.warn("No HELP URL configured, help system disabled.");
    }
    PINManagementGUIFacade gui = new PINManagementGUI(dialog.getContentPane(), dialog.getLocale(), null,
            new ResourceFontLoader(), helpListener);
    BKUGUIFacade proxy = (BKUGUIFacade) GUIProxy.newInstance(gui, dialog,
            new Class[] { PINManagementGUIFacade.class });
    SMCCHelper.setUseSWCard(configurationFacade.getUseSWCard());
    stal = new LocalBKUWorker(proxy, dialog);
    dialog.setPreferredSize(PREFERRED_SIZE);
    dialog.pack();
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    Dimension frameSize = dialog.getSize();
    if (frameSize.height > screenSize.height) {
        frameSize.height = screenSize.height;
    }
    if (frameSize.width > screenSize.width) {
        frameSize.width = screenSize.width;
    }
    dialog.setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2);
    return stal;
}

From source file:com.diversityarrays.kdxplore.curate.fieldview.OverviewDialog.java

@SuppressWarnings("unchecked")
public OverviewDialog(Window window, String title,

        @SuppressWarnings("rawtypes") ComboBoxModel comboBoxModel, CurationData curationData,
        Transformer<TraitInstance, String> tiNameProvider, OverviewInfoProvider overviewInfoProvider,
        FieldViewSelectionModel fvsm, FieldLayoutTableModel fltm, CurationTableModel ctm) {
    super(window, title, ModalityType.MODELESS);

    setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
    setAlwaysOnTop(true);/*w ww .  java 2s.  com*/

    this.fieldViewSelectionModel = fvsm;

    @SuppressWarnings({ "rawtypes" })
    JComboBox activeTiCombo = new JComboBox(comboBoxModel);
    TraitInstanceCellRenderer tiCellRenderer = new TraitInstanceCellRenderer(
            curationData.getTraitColorProvider(), tiNameProvider);
    activeTiCombo.setRenderer(tiCellRenderer);

    JLabel infoLabel = new JLabel(" ");
    infoLabel.setBorder(new BevelBorder(BevelBorder.LOWERED));

    final JFrame[] helpDialog = new JFrame[1];
    Action helpAction = new AbstractAction("?") {
        @Override
        public void actionPerformed(ActionEvent e) {
            if (helpDialog[0] != null) {
                GuiUtil.restoreFrame(helpDialog[0]);
            } else {
                JFrame f = new JFrame("Overview Help");
                helpDialog[0] = f;
                f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
                f.setAlwaysOnTop(true);
                f.setLocationRelativeTo(overview);
                String html = Overview.getOverviewHelpHtml();
                JLabel label = new JLabel(html);
                label.setBorder(new EmptyBorder(0, 10, 0, 10));
                f.setContentPane(label);
                f.pack();
                f.setVisible(true);
            }
        }
    };

    //        Window window = GuiUtil.getOwnerWindow(FieldLayoutViewPanel.this);
    if (window != null) {
        if (window instanceof JFrame) {
            System.out.println("Found window: " + ((JFrame) window).getTitle());
        }
        window.addWindowListener(new WindowAdapter() {
            @Override
            public void windowClosed(WindowEvent e) {
                window.removeWindowListener(this);
                if (helpDialog[0] != null) {
                    helpDialog[0].dispose();
                }
            }
        });
    }

    KDClientUtils.initAction(ImageId.HELP_24, helpAction, "Help for Overview");
    Box top = Box.createHorizontalBox();
    top.add(activeTiCombo);
    top.add(new JButton(helpAction));

    overview = new Overview(overviewInfoProvider, fltm, curationData, ctm, infoLabel);
    overview.setActiveTraitInstance(fvsm.getActiveTraitInstance(true));
    Container cp = getContentPane();

    cp.add(top, BorderLayout.NORTH);
    //      cp.add(traitLabel, BorderLayout.NORTH);
    cp.add(infoLabel, BorderLayout.SOUTH);
    cp.add(overview, BorderLayout.CENTER);

    pack();
    //      setResizable(false);

    //      setLocationRelativeTo(showOverviewButton);
    // DEFAULT POSITION is "out of the way"
    setVisible(true);

    this.fieldViewSelectionModel.addListSelectionListener(listSelectionListener);

    addWindowListener(new WindowAdapter() {
        @Override
        public void windowOpened(WindowEvent e) {
            toFront();
        }

        @Override
        public void windowClosed(WindowEvent e) {
            fieldViewSelectionModel.removeListSelectionListener(listSelectionListener);
            removeWindowListener(this);
        }
    });
}