Example usage for javax.swing JFrame isVisible

List of usage examples for javax.swing JFrame isVisible

Introduction

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

Prototype

@Transient
public boolean isVisible() 

Source Link

Document

Determines whether this component should be visible when its parent is visible.

Usage

From source file:Main.java

public static void main(String[] args) {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JDialog dialog = new JDialog(frame, false);
    dialog.setSize(200, 50);/*from w  w w.  j  a va 2 s .  c  o  m*/
    frame.addComponentListener(new ComponentAdapter() {
        Point lastLocation;

        @Override
        public void componentMoved(ComponentEvent e) {
            if (lastLocation == null && frame.isVisible()) {
                lastLocation = frame.getLocation();
            } else {
                Point newLocation = frame.getLocation();
                int dx = newLocation.x - lastLocation.x;
                int dy = newLocation.y - lastLocation.y;
                dialog.setLocation(dialog.getX() + dx, dialog.getY() + dy);
                lastLocation = newLocation;
            }
        }
    });
    frame.setSize(400, 200);
    frame.setVisible(true);
    dialog.setLocationRelativeTo(frame);
    dialog.setVisible(true);
}

From source file:Main.java

/**
 * @return Returns <code>true</code> if the frame is visible, showing and not
 *         iconified.//from ww w  .  j ava2 s. c  o  m
 */
public static boolean isVisibleNotMinimized(JFrame frame) {
    assertEventDispatcherThread();

    return (frame.isVisible() && frame.isShowing() && (frame.getExtendedState() & JFrame.ICONIFIED) == 0);
}

From source file:OAT.ui.util.UiUtil.java

public static void toggleFrame(JFrame frame) {
    if (frame == null) {
        return;/*from  w w w. j a  v a  2 s .c  om*/
    }

    frame.setVisible(!frame.isVisible());

    //        if (frame.isVisible()) {
    //            if (frame.isFocusOwner()) {
    //                frame.setVisible(false);
    //            } else {
    //                frame.toFront();
    //            }
    //        } else {
    //            frame.setVisible(true);
    //        }
}

From source file:de.jakop.ngcalsync.application.TrayStarter.java

private MouseAdapter createLogMouseListener(final JFrame logWindow) {
    return new MouseAdapter() {

        @Override/*  w  ww .j  a  v  a2 s.co m*/
        public void mouseClicked(final MouseEvent e) {
            if (e.getClickCount() == 1 && e.getButton() == MouseEvent.BUTTON1) {
                logWindow.setVisible(!logWindow.isVisible());
            }
        }

    };
}

From source file:ca.nengo.plot.impl.DefaultPlotter.java

public void doPlotMSE(NEFEnsemble ensemble, DecodedOrigin origin, String name) {
    float[] error = new float[origin.getDimensions()];
    float mseAvg; //MSE for all of the dimensions of the origin together

    JPanel panel = new JPanel();
    JFrame frame = createFrame();
    frame.setVisible(true);/*  ww  w. j ava 2  s  .c o m*/
    long time = System.currentTimeMillis() - 21;

    //plot MSE on continuously updating graph as more samples are used in the calculation
    for (int i = 1; i == 1 || frame.isVisible(); i++) { //will crash if runtime exceeds 4.1 years
        //synchronized(ensemble){
        error = MU.sum(MU.prod(error, ((i - 1f) / i)), MU.prod(origin.getError(1), 1f / i));
        //}
        mseAvg = MU.mean(error);
        if ((System.currentTimeMillis() - time) > 20l) { //frame limiter
            panel = getBarChart(error, "MSE per Dimension for Origin: " + origin.getName());
            frame.getContentPane().removeAll();
            frame.getContentPane().add(panel, BorderLayout.CENTER);
            frame.setTitle("Origin MSE Plot (Overall MSE=" + mseAvg + ")");
            frame.validate();

            time = System.currentTimeMillis();
        }
        if (i == 1) {
            frame.pack();
            frame.setVisible(true);
        }
    }
}

From source file:org.nebulaframework.ui.swing.cluster.ClusterMainUI.java

/**
 * System Tray Icon setup/*  w ww. j a  va2 s.  co m*/
 * @param frame owner JFrame
 */
private void setupTrayIcon(final JFrame frame) {

    // Idle Icon
    idleIcon = Toolkit.getDefaultToolkit()
            .getImage(ClassLoader.getSystemResource("META-INF/resources/cluster_inactive.png"));

    // Active Icon
    activeIcon = Toolkit.getDefaultToolkit()
            .getImage(ClassLoader.getSystemResource("META-INF/resources/cluster_active.png"));

    frame.setIconImage(idleIcon);

    // If system tray is supported by OS
    if (SystemTray.isSupported()) {

        // Set Icon
        trayIcon = new TrayIcon(idleIcon, "Nebula Grid Cluster", createTrayPopup());
        trayIcon.setImageAutoSize(true);
        trayIcon.addMouseListener(new MouseAdapter() {

            @Override
            public void mouseClicked(MouseEvent e) {
                if (e.getButton() == MouseEvent.BUTTON1) {
                    if (!frame.isVisible()) {
                        frame.setVisible(true);
                    }

                    frame.setExtendedState(JFrame.NORMAL);
                    frame.requestFocus();
                    frame.toFront();
                }
            }

        });

        try {
            SystemTray.getSystemTray().add(trayIcon);
        } catch (AWTException ae) {
            log.debug("[UI] Unable to Initialize Tray Icon");
            return;
        }

        frame.addWindowListener(new WindowAdapter() {

            @Override
            public void windowIconified(WindowEvent e) {
                // Hide (can be shown using tray icon)
                frame.setVisible(false);
            }

        });
    }

}

From source file:edu.ku.brc.specify.tasks.subpane.wb.WorkbenchPaneSS.java

/**
 * Shows / Hides the Image Window. /*from   ww  w  .  j  av a  2s.c o m*/
 */
public void setImageFrameVisible(final boolean visible, final JFrame imgFrame, final JButton toolBtn,
        final String ttHelpVisible, final String ttHelpHidden, final String helpContext) {
    if (visible == imgFrame.isVisible()) {
        return;
    }

    if (spreadSheet.getCellEditor() != null) {
        spreadSheet.getCellEditor().stopCellEditing();
    }

    // and add or remove the ListSelectionListener (to avoid loading images when not visible)
    if (!visible) {
        spreadSheet.setTransferHandler(null);

        // hide the image window

        // turn off alwaysOnTop for Swing repaint reasons (prevents a lock up)
        if (imgFrame.isAlwaysOnTop()) {
            imgFrame.setAlwaysOnTop(false);
        }
        // if the image frame is minimized or iconified, set it to fully visible before doing anything else
        if (imgFrame.getState() == Frame.ICONIFIED) {
            imgFrame.setState(Frame.NORMAL);
        }
        toolBtn.setToolTipText(getResourceString(ttHelpVisible));

        spreadSheet.getSelectionModel().removeListSelectionListener(workbenchRowChangeListener);

        // set the image window and the image column invisible
        imgFrame.setVisible(false);
        imageColExt.setVisible(false);
    } else {
        spreadSheet.setTransferHandler(new WBImageTransferable());

        // show the image window

        UIHelper.positionFrameRelativeToTopFrame(imgFrame);

        // when a user hits the "show image" button, for some reason the selection gets nullified
        // so we'll grab it here, then set it at the end of this method

        toolBtn.setToolTipText(getResourceString(ttHelpHidden));

        spreadSheet.getSelectionModel().addListSelectionListener(workbenchRowChangeListener);
        HelpMgr.setHelpID(this, helpContext);

        // set the image window and the image column visible
        imgFrame.setVisible(true);
        imageColExt.setVisible(true);

        // if the image frame is minimized or iconified, set it to fully visible before doing anything else
        if (imgFrame.getState() == Frame.ICONIFIED) {
            imgFrame.setState(Frame.NORMAL);
        }

        showCardImageForSelectedRow();

        // Without this code below the Image Column doesn't get selected
        // when toggling 
        if (currentPanelType == PanelType.Spreadsheet && currentRow != -1) {
            spreadSheet.setRowSelectionInterval(currentRow, currentRow);
            spreadSheet.setColumnSelectionInterval(0, spreadSheet.getColumnCount() - 1);
            spreadSheet.scrollToRow(Math.min(currentRow + 4, model.getRowCount()));
        }

        TableColumn column = spreadSheet.getTableHeader().getColumnModel()
                .getColumn(spreadSheet.getTableHeader().getColumnModel().getColumnCount() - 1);
        column.setCellRenderer(new WbCellRenderer());
        spreadSheet.repaint();
    }
}

From source file:Tcpbw100.java

public void init() {

    //added applet parameters (country,language) to directly influence the language displayed
    if (getParameter("country") != null)
        country = getParameter("country");
    if (getParameter("language") != null)
        lang = getParameter("language");
    if (getParameter("client") != null)
        applet_id = getParameter("client");
    // try to load the appropriate resource files
    try {/*w ww  .  j  a  v  a2s . com*/
        locale = new Locale(lang, country);
        System.out.println("Interface language set to " + locale.getLanguage() + "_" + locale.getCountry());
        messages = ResourceBundle.getBundle("Tcpbw100_msgs", locale);
        res = ResourceBundle.getBundle("strings", locale);
        System.out.println("language loaded is :" + res.getLocale());
    } catch (Exception e) {
        JOptionPane.showMessageDialog(null, "Error while loading language files:\n" + e.getMessage());
        e.printStackTrace();
    }

    JPanel advancedPanel = new JPanel(new BorderLayout());
    final CardLayout cards = new CardLayout();
    getContentPane().setLayout(cards);

    final JFrame popout = new JFrame("Network Diagnostic Tool");
    popout.add(advancedPanel);
    popout.pack();

    //blank the labels
    reset_labels();

    showStatus(messages.getString("ready"));
    failed = false;
    Randomize = false;
    cancopy = false;
    results = new MyTextPane();
    results.append("TCP/Web100 Network Diagnostic Tool v" + VERSION + "\n");
    results.setEditable(false);
    advancedPanel.add(new JScrollPane(results), BorderLayout.CENTER);
    results.append(messages.getString("clickStart") + "\n");
    Panel mPanel = new Panel();
    startTest = new JButton(messages.getString("start"));
    startTest.addActionListener(this);
    startTest2 = new JButton(res.getString("start"));
    startTest2.addActionListener(this);

    //mPanel.add(startTest);
    sTatistics = new JButton(messages.getString("statistics"));
    sTatistics.addActionListener(this);
    if (getParameter("disableStatistics") == null) {
        mPanel.add(sTatistics);
    }
    sTatistics.setEnabled(false);
    deTails = new JButton(messages.getString("moreDetails"));
    deTails.addActionListener(this);
    if (getParameter("disableDetails") == null) {
        mPanel.add(deTails);
    }
    deTails.setEnabled(false);
    mailTo = new JButton(messages.getString("reportProblem"));
    mailTo.addActionListener(this);
    if (getParameter("disableMailto") == null) {
        //mPanel.add(mailTo);
    }
    mailTo.setEnabled(false);
    options = new JButton(messages.getString("options") + "...");
    options.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            options.setEnabled(false);
            showOptions();
            options.setEnabled(true);
        }

    });
    if (getParameter("disableOptions") == null) {
        mPanel.add(options);
    }
    advancedPanel.add(mPanel, BorderLayout.SOUTH);
    preferIPv6 = new JCheckBox(messages.getString("preferIPv6"));
    preferIPv6.setSelected(true);
    defaultTest = new JCheckBox(messages.getString("defaultTests"));
    defaultTest.setSelected(true);
    defaultTest.setEnabled(false);
    SpinnerNumberModel model = new SpinnerNumberModel();
    model.setMinimum(new Integer(0));
    model.setValue(new Integer(1));
    numOfTests.setModel(model);
    numOfTests.setPreferredSize(new Dimension(60, 20));
    delay = new JComboBox();
    for (int i = 0; i < delays.length; i++) {
        delay.addItem(messages.getString(delays[i]));
    }
    delay.setSelectedIndex(0);

    //Autorun functionality
    isAutoRun = getParameter("autoRun");
    if ((isAutoRun != null) && isAutoRun.equals("true")) {
        pub_errmsg = "Test in progress.";
        runtest();
    }
    //@@@ getContentPane().add(advancedPanel,"");

    //try to load the calibri font for the simplified interface.
    //this will not cause problems even if said font is not available
    Font very_small_font = new Font("Calibri", Font.PLAIN, 6);
    Font small_font = new Font("Calibri", Font.PLAIN, 14);
    Font big_font = new Font("Calibri", Font.PLAIN, 18);

    startTest2.setFont(small_font);

    //simplePanel will be the new face of the applet
    JPanel simplePanel = new JPanel();

    simplePanel.setLayout(null);
    simplePanel.setBackground(Color.WHITE);
    //simplePanel.setLayout(new BorderLayout());
    simplePanel.add(simple_progressBar, BorderLayout.SOUTH);
    getContentPane().add(simplePanel, "");
    cards.last(getContentPane());
    simple_progressBar.setMaximum(10);
    simple_progressBar.setBounds(3, 135, 394, 23);
    simple_progressBar.setFont(small_font);

    //simple_progressBar.setIndeterminate(true);
    simple_progressBar.setIndeterminate(false);
    simple_progressBar.setValue(0);
    simple_progressBar.setStringPainted(true);
    simple_progressBar.setString(res.getString("ready_to_measure"));

    //position the startTest2 button explicitly
    //was: simplePanel.add(startTest2,BorderLayout.NORTH);
    simplePanel.add(startTest2, "");
    startTest2.setBounds(3, 164, 195, 30);

    final class switcherListener implements ActionListener {
        public void actionPerformed(ActionEvent e) {
            //@@@cards.next(getContentPane());
            if (popout.isVisible()) {
                popout.setVisible(false);
            } else {
                popout.setVisible(true);
                popout.pack();
            }

        }

    }

    //"show details button" - activates the classic NDT interface 
    JButton switchPane = new JButton(res.getString("show_details"));
    switchPane.setFont(small_font);

    switchPane.addActionListener(new switcherListener());
    simplePanel.add(switchPane, "");
    switchPane.setBounds(202, 164, 195, 30);

    //masterArea, displays the measurement characteristics
    JPanel masterArea = new JPanel(new GridLayout(0, 2));

    //position explicitly
    simplePanel.add(masterArea, "");
    masterArea.setBounds(1, 1, 398, 130);
    masterArea.setBackground(Color.WHITE);

    //create the 5 tags that will be placed in the masterArea
    JLabel dnlTag = new JLabel(res.getString("download"));
    JLabel uplTag = new JLabel(res.getString("upload"));
    JLabel rttTag = new JLabel(res.getString("ping"));
    JLabel lossTag = new JLabel(res.getString("loss"));
    JLabel jitterTag = new JLabel(res.getString("jitter"));

    //make the masterAre pretty  
    dnlTag.setHorizontalAlignment(JLabel.RIGHT);
    uplTag.setHorizontalAlignment(JLabel.RIGHT);
    rttTag.setHorizontalAlignment(JLabel.RIGHT);
    lossTag.setHorizontalAlignment(JLabel.RIGHT);
    jitterTag.setHorizontalAlignment(JLabel.RIGHT);

    dnlTag.setFont(big_font);
    uplTag.setFont(big_font);
    rttTag.setFont(big_font);
    lossTag.setFont(big_font);
    jitterTag.setFont(big_font);

    dnlLbl.setHorizontalAlignment(JLabel.LEFT);
    uplLbl.setHorizontalAlignment(JLabel.LEFT);
    rttLbl.setHorizontalAlignment(JLabel.LEFT);
    lossLbl.setHorizontalAlignment(JLabel.LEFT);
    jitterLbl.setHorizontalAlignment(JLabel.LEFT);

    dnlLbl.setFont(big_font);
    uplLbl.setFont(big_font);
    rttLbl.setFont(big_font);
    lossLbl.setFont(big_font);
    jitterLbl.setFont(big_font);

    //and finally, place the labels
    masterArea.add(dnlTag);
    masterArea.add(dnlLbl);
    masterArea.add(uplTag);
    masterArea.add(uplLbl);
    masterArea.add(rttTag);
    masterArea.add(rttLbl);
    masterArea.add(lossTag);
    masterArea.add(lossLbl);
    masterArea.add(jitterTag);
    masterArea.add(jitterLbl);

    // determine whether to prefer IPv6 or not, this is done only once
    if (getParameter("disable_ipv6") != null) {
        preferIPv6.setSelected(false);
    }

}

From source file:org.nebulaframework.ui.swing.node.NodeMainUI.java

/**
 * Setup System Tray Icon./*from  w  w  w  .  jav  a  2  s . c om*/
 * 
 * @param frame owner frame
 */
private void setupTrayIcon(final JFrame frame) {

    idleIcon = Toolkit.getDefaultToolkit()
            .getImage(ClassLoader.getSystemResource("META-INF/resources/node_inactive.png"));

    activeIcon = Toolkit.getDefaultToolkit()
            .getImage(ClassLoader.getSystemResource("META-INF/resources/node_active.png"));

    frame.setIconImage(idleIcon);

    // If system tray is supported by OS
    if (SystemTray.isSupported()) {
        trayIcon = new TrayIcon(idleIcon, "Nebula Grid Node", createTrayPopup());
        trayIcon.setImageAutoSize(true);
        trayIcon.addMouseListener(new MouseAdapter() {

            @Override
            public void mouseClicked(MouseEvent e) {
                if (e.getButton() == MouseEvent.BUTTON1) {
                    if (!frame.isVisible()) {
                        frame.setVisible(true);
                    }

                    frame.setExtendedState(JFrame.NORMAL);
                    frame.requestFocus();
                    frame.toFront();
                }
            }

        });

        try {
            SystemTray.getSystemTray().add(trayIcon);
        } catch (AWTException ae) {
            log.debug("[UI] Unable to Initialize Tray Icon");
            return;
        }

        frame.addWindowListener(new WindowAdapter() {

            @Override
            public void windowIconified(WindowEvent e) {
                // Hide (can be shown using tray icon)
                frame.setVisible(false);
            }

        });
    }

}