Example usage for javax.swing JFrame getSize

List of usage examples for javax.swing JFrame getSize

Introduction

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

Prototype

public Dimension getSize() 

Source Link

Document

Returns the size of this component in the form of a Dimension object.

Usage

From source file:com.mirth.connect.plugins.imageviewer.ImageViewer.java

public void viewAttachments(String channelId, Long messageId, String attachmentId) {

    JFrame frame = new JFrame("Image Viewer");

    try {//from ww w  .  j  av a  2  s .co m

        Attachment attachment = parent.mirthClient.getAttachment(channelId, messageId, attachmentId);
        byte[] rawData = attachment.getContent();
        ByteArrayInputStream bis = new ByteArrayInputStream(rawData);

        image = ImageIO.read(new Base64InputStream(bis));

        JScrollPane pictureScrollPane = new JScrollPane(new JLabel(new ImageIcon(image)));
        pictureScrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
        pictureScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
        frame.add(pictureScrollPane);

        frame.addWindowListener(new WindowAdapter() {

            public void windowClosing(WindowEvent e) {
                e.getWindow().dispose();
            }
        });

        frame.pack();

        int imageWidth = image.getWidth();
        int imageHeight = image.getHeight();

        // Resize the frame so that it fits and scrolls images larger than
        // 800x600 properly.
        if (imageWidth > 800 || imageHeight > 600) {
            int width = imageWidth;
            int height = imageHeight;
            if (imageWidth > 800) {
                width = 800;
            }
            if (imageHeight > 600) {
                height = 600;
            }

            // Also add the scrollbars to the window width if necessary.
            Integer scrollBarWidth = (Integer) UIManager.get("ScrollBar.width");
            int verticalScrollBar = 0;
            int horizontalScrollBar = 0;

            if (width == 800) {
                horizontalScrollBar = scrollBarWidth.intValue();
            }
            if (height == 600) {
                verticalScrollBar = scrollBarWidth.intValue();
            }

            // Also add the window borders to the width.
            width = width + frame.getInsets().left + frame.getInsets().right + verticalScrollBar;
            height = height + frame.getInsets().top + frame.getInsets().bottom + horizontalScrollBar;

            frame.setSize(width, height);
        }

        Dimension dlgSize = frame.getSize();
        Dimension frmSize = parent.getSize();
        Point loc = parent.getLocation();

        if ((frmSize.width == 0 && frmSize.height == 0) || (loc.x == 0 && loc.y == 0)) {
            frame.setLocationRelativeTo(null);
        } else {
            frame.setLocation((frmSize.width - dlgSize.width) / 2 + loc.x,
                    (frmSize.height - dlgSize.height) / 2 + loc.y);
        }

        frame.setVisible(true);
    } catch (Exception e) {
        parent.alertThrowable(parent, e);
    }
}

From source file:org.gridchem.client.GridChem.java

public static void main(String[] args) {
    Trace.entry();//w w w.  j  av a 2 s.  com

    try {
        setCommandLineOptions();
        parseCommandLine(args);
    } catch (Exception e) {
        System.out.println("Invalid command line option given: " + e.getMessage());
    }

    //JFrame.setDefaultLookAndFeelDecorated(true);
    JFrame frame = new JFrame();

    // Edited by Shashank & Sandeep @ CCS,UKY April 10 2005
    JFrame.setDefaultLookAndFeelDecorated(true);
    JDialog.setDefaultLookAndFeelDecorated(true);
    /*MetalTheme theme = new G03Input.ColorTheme();  
    MetalLookAndFeel.setCurrentTheme(theme);
    try {
        UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
        SwingUtilities.updateComponentTreeUI(frame);
    } catch(Exception e) {
        System.out.println(e);
    }*/

    // Use the native look and feel since Java's is pretty lame.
    try {
        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    } catch (Exception e) {
        // Ignore exceptions, which only result in the wrong look and feel.
        System.out.println("GridChem.main: an exception related to the" + " look and feel was ignored.");
    }

    init();

    frame.setTitle("GridChem " + Env.getVersion());
    frame.getContentPane().add(oc);
    frame.addWindowListener(new WindowListener() {

        public void windowActivated(WindowEvent arg0) {
        }

        public void windowClosed(WindowEvent arg0) {
        }

        public void windowClosing(WindowEvent arg0) {
            if (Settings.authenticated) {
                GMS3.logout();
            }
        }

        public void windowDeactivated(WindowEvent arg0) {
        }

        public void windowDeiconified(WindowEvent arg0) {
        }

        public void windowIconified(WindowEvent arg0) {
        }

        public void windowOpened(WindowEvent arg0) {
        }

    });
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.pack();

    // Centering the frame on the screen
    Toolkit kit = frame.getToolkit();
    Dimension screenSize = kit.getScreenSize();
    int screenWidth = screenSize.width;
    int screenHeight = screenSize.height;
    Dimension windowSize = frame.getSize();
    int windowWidth = windowSize.width;
    int windowHeight = windowSize.height;
    int upperLeftX = (screenWidth - windowWidth) / 2;
    int upperLeftY = (screenHeight - windowHeight) / 2;
    frame.setLocation(upperLeftX, upperLeftY);
    frame.setVisible(true);

    Trace.exit();
}

From source file:org.zaproxy.zap.extension.openapi.ImportFromUrlDialog.java

public ImportFromUrlDialog(JFrame parent, ExtensionOpenApi caller) {
    super(parent, true);
    this.setTitle(Constant.messages.getString(MESSAGE_PREFIX + "title"));
    this.caller = caller;
    if (parent != null) {
        Dimension parentSize = parent.getSize();
        Point p = parent.getLocation();
        setLocation(p.x + parentSize.width / 4, p.y + parentSize.height / 4);
    }/*from  www .  j a  v a  2  s.c o m*/
    // set up layout
    setLayout(new GridBagLayout());
    GridBagConstraints constraints = new GridBagConstraints();
    constraints.anchor = GridBagConstraints.WEST;
    constraints.insets = new Insets(5, 5, 5, 5);

    buttonImport.addActionListener(this);
    buttonCancel.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            ImportFromUrlDialog.this.setVisible(false);
            ImportFromUrlDialog.this.dispose();
        }
    });

    // add components to the frame
    constraints.gridx = 0;
    constraints.gridy = 0;
    add(new JLabel(Constant.messages.getString(MESSAGE_PREFIX + "labelurl")), constraints);

    constraints.gridx = 1;
    constraints.fill = GridBagConstraints.HORIZONTAL;
    constraints.weightx = 1.0;
    constraints.gridwidth = 2;
    fieldURL = addContextMenu(fieldURL);
    add(fieldURL, constraints);

    constraints.gridx = 0;
    constraints.gridy = 1;
    add(new JLabel(Constant.messages.getString(MESSAGE_PREFIX + "labeloverride")), constraints);

    constraints.gridx = 1;
    constraints.fill = GridBagConstraints.HORIZONTAL;
    constraints.weightx = 1.0;
    constraints.gridwidth = 2;
    add(siteOverride, constraints);

    constraints.gridwidth = 1;
    constraints.gridy = 2;
    constraints.anchor = GridBagConstraints.CENTER;
    add(buttonCancel, constraints);
    constraints.gridx = 2;
    constraints.gridy = 2;
    constraints.anchor = GridBagConstraints.CENTER;
    add(buttonImport, constraints);

    setDefaultCloseOperation(DISPOSE_ON_CLOSE);
    pack();
    setVisible(true);
}

From source file:phex.Main.java

/**
 * /*from  w w  w .j a  v a2  s  .  c o  m*/
 */
private static void validateJavaVersion() {
    if (SystemUtils.isJavaVersionAtLeast(1.5f)) {
        return;
    }

    JFrame frame = new JFrame("Wrong Java Version");
    frame.setSize(new Dimension(0, 0));
    frame.setVisible(true);
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    Dimension winSize = frame.getSize();
    Rectangle rect = new Rectangle((screenSize.width - winSize.width) / 2,
            (screenSize.height - winSize.height) / 2, winSize.width, winSize.height);
    frame.setBounds(rect);
    JOptionPane.showMessageDialog(frame,
            "Please use a newer Java VM.\n" + "Phex requires at least Java 1.5.0. You are using Java "
                    + SystemUtils.JAVA_VERSION + "\n" + "To get the latest Java release go to http://java.com.",
            "Wrong Java Version", JOptionPane.WARNING_MESSAGE);
    System.exit(1);
}

From source file:uk.ac.abdn.csd.p2p.server.ServerGUI.java

/**
 * This method prepares all the graphical components that are contained with P2P Visualisation Server.
 *///w w  w . j av a  2s .co  m
// <editor-fold defaultstate="collapsed" desc="...GUI">
private void initializeComponent() {
    listeningPort = 0;

    JFrame frame = new JFrame();
    BorderLayout layout = new BorderLayout();

    //create a graph
    overlay = new UndirectedSparseGraph<Vertex, Edge>();
    ObservableGraph<Vertex, Edge> og = new ObservableGraph<Vertex, Edge>(overlay);
    /*   og.addGraphEventListener(new GraphEventListener<Vertex, Edge>() {
       @Override
       public void handleGraphEvent(
       GraphEvent<Vertex, Edge> evt) {
    System.err.println("got " + evt);
            
       }
    });*/
    this.overlay = og;
    layout1 = new FRLayout2<Vertex, Edge>(overlay);
    vv = new VisualizationViewer<Vertex, Edge>(layout1, new Dimension(700, 200));
    vv.setGraphMouse(new DefaultModalGraphMouse<Vertex, Edge>());
    vv.getRenderContext().setVertexLabelTransformer(new ToStringLabeller<Vertex>());
    vv.getRenderContext().setEdgeLabelTransformer(new ToStringLabeller<Edge>());
    vv.getRenderer().getVertexLabelRenderer().setPosition(Position.CNTR);
    vv.getRenderContext().setVertexFillPaintTransformer(new VertexPainter());

    DefaultModalGraphMouse gm1 = new DefaultModalGraphMouse();
    gm1.setMode(ModalGraphMouse.Mode.TRANSFORMING);
    gm1.setMode(ModalGraphMouse.Mode.PICKING);
    gm1.add(new MyPopupGraphMousePlugin());
    vv.setGraphMouse(gm1);
    vv.addKeyListener(gm1.getModeKeyListener());

    contentPane = new JPanel(layout);

    displayPanel = new javax.swing.JPanel();

    consoleTextArea = new JTextArea();
    jScrollPane2 = new JScrollPane();
    clearButton = new JButton();
    consolePanel = new JPanel();
    clearButton = new javax.swing.JButton();

    nodeTextArea = new JTextArea();
    jScrollPane1 = new JScrollPane();
    nodePanel = new JPanel();

    linkTextArea = new JTextArea();
    jScrollPane3 = new JScrollPane();
    linkPanel = new JPanel();

    menuBar = new javax.swing.JMenuBar();
    serverMenu = new javax.swing.JMenu();
    startServerMenuItem = new javax.swing.JMenuItem();
    jSeparator1 = new javax.swing.JPopupMenu.Separator();
    exitMenuItem = new javax.swing.JMenuItem();
    editMenu = new javax.swing.JMenu();
    settingMenuItem = new javax.swing.JMenuItem();
    colorSettingMenuItem = new javax.swing.JMenuItem();
    toolMenuItem = new javax.swing.JMenu();
    clearMenuItem = new javax.swing.JMenuItem();
    helpMenu = new javax.swing.JMenu();
    aboutMenuItem = new javax.swing.JMenuItem();
    zoominMenuItem = new javax.swing.JMenuItem();
    zoomoutMenuItem = new javax.swing.JMenuItem();
    layoutSettingMenuItem = new javax.swing.JMenuItem();
    labelPositionMenuItem = new javax.swing.JMenuItem();
    speedSettingMenuItem = new javax.swing.JMenuItem();
    topologySettingMenuItem = new javax.swing.JMenuItem();
    findNodeMenuItem = new javax.swing.JMenuItem();

    serverMenu.setText("Server");
    serverMenu.setToolTipText("Server");

    startServerMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_C,
            java.awt.event.InputEvent.ALT_MASK));
    startServerMenuItem.setText("Start Server");
    startServerMenuItem.setToolTipText("Start Server");
    startServerMenuItem.addActionListener(new java.awt.event.ActionListener() {
        @Override
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            startServerMenuItemActionPerformed(evt);
        }
    });
    serverMenu.add(startServerMenuItem);
    serverMenu.add(jSeparator1);

    exitMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_X,
            java.awt.event.InputEvent.ALT_MASK));
    exitMenuItem.setText("Exit");
    exitMenuItem.setToolTipText("Exit");
    exitMenuItem.addActionListener(new java.awt.event.ActionListener() {
        @Override
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            exitMenuItemActionPerformed(evt);
        }
    });
    serverMenu.add(exitMenuItem);

    menuBar.add(serverMenu);

    editMenu.setText("Edit");
    editMenu.setToolTipText("Edit");

    settingMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_S,
            java.awt.event.InputEvent.ALT_MASK));
    settingMenuItem.setText("Server Settings");
    settingMenuItem.setToolTipText("Server Settings");
    settingMenuItem.addActionListener(new java.awt.event.ActionListener() {
        @Override
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            settingMenuItemActionPerformed(evt);
        }
    });
    editMenu.add(settingMenuItem);

    colorSettingMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_M,
            java.awt.event.InputEvent.ALT_MASK));
    colorSettingMenuItem.setText("Colour Settings");
    colorSettingMenuItem.setToolTipText("Colour Settings");
    colorSettingMenuItem.addActionListener(new java.awt.event.ActionListener() {
        @Override
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            colorSettingMenuItemActionPerformed(evt);
        }
    });
    editMenu.add(colorSettingMenuItem);

    layoutSettingMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_L,
            java.awt.event.InputEvent.ALT_MASK));
    layoutSettingMenuItem.setText("Layout Settings");
    layoutSettingMenuItem.setToolTipText("Layout Settings");
    layoutSettingMenuItem.addActionListener(new java.awt.event.ActionListener() {
        @Override
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            layoutSettingMenuItemActionPerformed(evt);
        }
    });
    editMenu.add(layoutSettingMenuItem);

    speedSettingMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_V,
            java.awt.event.InputEvent.ALT_MASK));
    speedSettingMenuItem.setText("Speed Settings");
    speedSettingMenuItem.setToolTipText("Speed Settings");
    speedSettingMenuItem.addActionListener(new java.awt.event.ActionListener() {
        @Override
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            speedSettingMenuItemActionPerformed(evt);
        }
    });
    editMenu.add(speedSettingMenuItem);

    topologySettingMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_T,
            java.awt.event.InputEvent.ALT_MASK));
    topologySettingMenuItem.setText("Topology Settings");
    topologySettingMenuItem.setToolTipText("Topology Settings");
    topologySettingMenuItem.addActionListener(new java.awt.event.ActionListener() {
        @Override
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            topologySettingMenuItemActionPerformed(evt);
        }
    });
    editMenu.add(topologySettingMenuItem);

    menuBar.add(editMenu);

    toolMenuItem.setText("Tools");
    toolMenuItem.setToolTipText("Tools");

    labelPositionMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_P,
            java.awt.event.InputEvent.ALT_MASK));
    labelPositionMenuItem.setText("Vertex Label Position");
    labelPositionMenuItem.setToolTipText("Vertex Label Position");
    toolMenuItem.add(labelPositionMenuItem);
    labelPositionMenuItem.addActionListener(new java.awt.event.ActionListener() {
        @Override
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            labelPositionMenuItemActionPerformed(evt);

        }
    });

    final ScalingControl scaler = new CrossoverScalingControl();

    zoominMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_I,
            java.awt.event.InputEvent.ALT_MASK));
    zoominMenuItem.setText("Zoom-In");
    zoominMenuItem.setToolTipText("Zoom-In");
    toolMenuItem.add(zoominMenuItem);
    zoominMenuItem.addActionListener(new java.awt.event.ActionListener() {
        @Override
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            scaler.scale(vv, 1.1f, vv.getCenter());
        }
    });
    zoomoutMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_O,
            java.awt.event.InputEvent.ALT_MASK));
    zoomoutMenuItem.setText("Zoom-Out");
    zoomoutMenuItem.setToolTipText("Zoom-Out");
    toolMenuItem.add(zoomoutMenuItem);
    zoomoutMenuItem.addActionListener(new java.awt.event.ActionListener() {
        @Override
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            scaler.scale(vv, 0.9f, vv.getCenter());
        }
    });

    findNodeMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_F,
            java.awt.event.InputEvent.ALT_MASK));
    findNodeMenuItem.setText("Find Node on Overlay");
    findNodeMenuItem.setToolTipText("Find Node");
    toolMenuItem.add(findNodeMenuItem);
    findNodeMenuItem.addActionListener(new java.awt.event.ActionListener() {
        @Override
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            findNodeMenuItemMenuItemActionPerformed(evt);
        }
    });

    menuBar.add(toolMenuItem);

    helpMenu.setText("Help");
    helpMenu.setToolTipText("Help");

    aboutMenuItem.setText("About");
    aboutMenuItem.setToolTipText("About");
    aboutMenuItem.addActionListener(new java.awt.event.ActionListener() {
        @Override
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            aboutMenuItemActionPerformed(evt);
        }
    });
    helpMenu.add(aboutMenuItem);

    menuBar.add(helpMenu);

    displayPanel.setLayout(new BorderLayout());
    displayPanel.setBorder(new TitledBorder("P2P Overlay"));
    displayPanel.add(vv);
    validate();
    //
    // nodeTextArea
    //
    nodeTextArea.setEditable(false);
    nodeTextArea.setLineWrap(true);

    //
    // jScrollPane1
    //
    jScrollPane1.setViewportView(nodeTextArea);
    //jScrollPane1.setsi
    //
    // nodePanel
    //
    nodePanel.setLayout(new BoxLayout(nodePanel, BoxLayout.X_AXIS));
    nodePanel.add(jScrollPane1, 0);

    nodePanel.setBorder(new TitledBorder("Nodes Active"));
    //
    // linkTextArea
    //
    linkTextArea.setEditable(false);
    linkTextArea.setLineWrap(true);
    //
    // jScrollPane3
    //
    jScrollPane3.setViewportView(linkTextArea);
    //
    // linkPanel
    //
    linkPanel.setLayout(new BoxLayout(linkPanel, BoxLayout.X_AXIS));
    linkPanel.add(jScrollPane3, 0);
    linkPanel.setBorder(new TitledBorder("Node Links"));
    //
    // consoleTextArea
    //
    consoleTextArea.setEditable(false);
    consoleTextArea.setLineWrap(true);
    //
    // jScrollPane2
    //
    jScrollPane2.setViewportView(consoleTextArea);
    //
    // clearButton
    //
    clearButton.setText("Clear");
    clearButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            clearButton_actionPerformed(e);
        }

    });
    //
    // consolePanel
    //
    consolePanel.setLayout(new BoxLayout(consolePanel, BoxLayout.X_AXIS));
    consolePanel.add(jScrollPane2, 0);
    consolePanel.add(clearButton, 1);
    consolePanel.setBorder(new TitledBorder("Console"));
    //
    // ServerGUI
    //
    Dimension panelD = new Dimension(700, 330); // display Panel
    Dimension panelD1 = new Dimension(700, 134); // control Panel      
    Dimension panelD2 = new Dimension(350, 140); // nodepanel and linkpanel
    Dimension panelD3 = new Dimension(700, 140); // nodepanel and linkpanel togther
    consolePanel.setPreferredSize(panelD1);
    displayPanel.setPreferredSize(panelD);
    nodePanel.setPreferredSize(panelD2);
    linkPanel.setPreferredSize(panelD2);
    Box box = new Box(BoxLayout.X_AXIS); // put nodepanel and linkpanel in one box
    box.add(nodePanel);
    box.add(linkPanel);
    box.setSize(panelD3);

    //contentPane.add(BorderLayout.NORTH,displayPanel);
    //contentPane.add(BorderLayout.CENTER,box);
    contentPane.add(BorderLayout.NORTH, box);
    contentPane.add(BorderLayout.CENTER, displayPanel);
    contentPane.add(BorderLayout.SOUTH, consolePanel);

    frame.setJMenuBar(menuBar);
    frame.getContentPane().add(contentPane);
    frame.setTitle("P2P Visualisation Server");
    frame.setSize(new Dimension(800, 600));
    frame.setResizable(true);
    // This code has been adapted from http://lookass.ch/?id=4&area=art&art=47
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    Dimension size = frame.getSize();
    screenSize.height = screenSize.height / 2;
    screenSize.width = screenSize.width / 2;
    size.height = size.height / 2;
    size.width = size.width / 2;
    int y = screenSize.height - size.height;
    int x = screenSize.width - size.width;
    frame.setLocation(x, y);
    frame.setVisible(true);

    frame.setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
    frame.addWindowListener(new java.awt.event.WindowAdapter() {
        public void windowClosing(java.awt.event.WindowEvent evt) {
            formWindowClosing(evt);
        }
    });
}