Example usage for java.awt Dialog setResizable

List of usage examples for java.awt Dialog setResizable

Introduction

In this page you can find the example usage for java.awt Dialog setResizable.

Prototype

public void setResizable(boolean resizable) 

Source Link

Document

Sets whether this dialog is resizable by the user.

Usage

From source file:Main.java

public static Window showCentered(Component parent, Window window) {
    if (null == window)
        throw new IllegalArgumentException("window null");

    if (window instanceof Dialog) {
        Dialog dialog = (Dialog) window;

        boolean isResizable = dialog.isResizable();

        dialog.setResizable(true);
        dialog.pack();/*from   w  w w  .ja  va 2  s  . c  om*/
        dialog.setResizable(isResizable);
    } else {
        window.pack();
    }

    Dimension windowSize = window.getPreferredSize();

    int newX;
    int newY;

    if (null == parent) {
        Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();

        newX = (screen.width - windowSize.width) / 2;
        newY = (screen.height - windowSize.height) / 2;
    } else {
        Dimension parentSize = parent.getSize();
        Point loc = parent.getLocation();

        newX = (parentSize.width - windowSize.width) / 2 + loc.x;
        newY = (parentSize.height - windowSize.height) / 2 + loc.y;

        if (0 > newX)
            newX = 0;
        if (0 > newY)
            newY = 0;
    }

    window.setLocation(newX, newY);
    window.setVisible(true);

    return window;
}

From source file:org.wandora.application.gui.topicpanels.ProcessingTopicPanel.java

private void showRichErrorDialog(String msg) {
    final JTextArea area = new JTextArea();
    area.setFont(errorMessageFont);//from w  w w.j a v  a  2 s . com
    //area.setPreferredSize(new Dimension(520, 180));
    area.setEditable(false);
    area.setText(msg);

    // Make the JOptionPane resizable using the HierarchyListener
    area.addHierarchyListener(new HierarchyListener() {
        public void hierarchyChanged(HierarchyEvent e) {
            Window window = SwingUtilities.getWindowAncestor(area);
            if (window instanceof Dialog) {
                Dialog dialog = (Dialog) window;
                if (!dialog.isResizable()) {
                    dialog.setResizable(true);
                }
            }
        }
    });

    JScrollPane scroller = new JScrollPane(area);
    scroller.setPreferredSize(new Dimension(520, 180));
    JOptionPane.showMessageDialog(Wandora.getWandora(), scroller, "Errors", JOptionPane.PLAIN_MESSAGE);
}