Example usage for java.awt Dialog isResizable

List of usage examples for java.awt Dialog isResizable

Introduction

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

Prototype

public boolean isResizable() 

Source Link

Document

Indicates 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);/*from ww w  .  j a va2  s. c  om*/
        dialog.pack();
        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  ww  w .jav  a  2s  . c o m*/
    //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);
}