Example usage for javax.swing JDialog setSize

List of usage examples for javax.swing JDialog setSize

Introduction

In this page you can find the example usage for javax.swing JDialog setSize.

Prototype

public void setSize(Dimension d) 

Source Link

Document

The d.width and d.height values are automatically enlarged if either is less than the minimum size as specified by previous call to setMinimumSize .

Usage

From source file:Main.java

public static void main(String[] a) {
    JDialog f = new JDialog();
    f.addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            System.exit(0);//  ww w . j  a va  2 s .  c  o m
        }
    });

    JButton btOK = new JButton("Press Enter to click me, I am the default.");
    btOK.setToolTipText("Save and exit");
    f.getRootPane().setDefaultButton(btOK);

    JPanel p = new JPanel();
    p.add(btOK);
    p.add(new JButton("I am NOT the default."));
    f.getContentPane().add(p);

    f.pack();
    f.setSize(new Dimension(300, 200));

    f.setVisible(true);

}

From source file:DefaultButton.java

public static void main(String[] a) {
    JDialog f = new JDialog();
    f.addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            System.exit(0);//  w  w  w.j  av  a 2s . c  o m
        }
    });

    JButton btOK = new JButton("Press Enter to click me, I am the default.");
    btOK.setToolTipText("Save and exit");
    f.getRootPane().setDefaultButton(btOK);

    JPanel p = new JPanel();
    p.add(btOK);
    p.add(new JButton("I am NOT the default."));
    f.getContentPane().add(p);

    f.pack();
    f.setSize(new Dimension(300, 200));

    f.show();

}

From source file:org.duracloud.syncui.SyncUIDriver.java

/**
 * Note: The embedded Jetty server setup below is based on the example configuration in the Eclipse documentation:
 * https://www.eclipse.org/jetty/documentation/9.4.x/embedded-examples.html#embedded-webapp-jsp
 *//*from   www .  j  a  v a  2s.  c o m*/
private static void launchServer(final String url, final CloseableHttpClient client) {
    try {
        final JDialog dialog = new JDialog();
        dialog.setSize(new java.awt.Dimension(400, 75));
        dialog.setModalityType(ModalityType.MODELESS);
        dialog.setTitle("DuraCloud Sync");
        dialog.setLocationRelativeTo(null);

        JPanel panel = new JPanel();
        final JLabel label = new JLabel("Loading...");
        final JProgressBar progress = new JProgressBar();
        progress.setStringPainted(true);

        panel.add(label);
        panel.add(progress);
        dialog.add(panel);
        dialog.setVisible(true);

        port = SyncUIConfig.getPort();
        contextPath = SyncUIConfig.getContextPath();
        Server srv = new Server(port);

        // Setup JMX
        MBeanContainer mbContainer = new MBeanContainer(ManagementFactory.getPlatformMBeanServer());
        srv.addBean(mbContainer);

        ProtectionDomain protectionDomain = org.duracloud.syncui.SyncUIDriver.class.getProtectionDomain();
        String warFile = protectionDomain.getCodeSource().getLocation().toExternalForm();

        log.debug("warfile: {}", warFile);
        WebAppContext context = new WebAppContext();
        context.setContextPath(contextPath);
        context.setWar(warFile);
        context.setExtractWAR(Boolean.TRUE);

        Configuration.ClassList classlist = Configuration.ClassList.setServerDefault(srv);
        classlist.addBefore("org.eclipse.jetty.webapp.JettyWebXmlConfiguration",
                "org.eclipse.jetty.annotations.AnnotationConfiguration");

        context.setAttribute("org.eclipse.jetty.server.webapp.ContainerIncludeJarPattern",
                ".*/[^/]*servlet-api-[^/]*\\.jar$|.*/javax.servlet.jsp.jstl-.*\\.jar$|.*/[^/]*taglibs.*\\.jar$");

        srv.setHandler(context);

        new Thread(new Runnable() {
            @Override
            public void run() {
                createSysTray(url, srv);

                while (true) {
                    if (progress.getValue() < 100) {
                        progress.setValue(progress.getValue() + 3);
                    }

                    sleep(2000);
                    if (isAppRunning(url, client)) {
                        break;
                    }
                }

                progress.setValue(100);

                label.setText("Launching browser...");
                launchBrowser(url);
                dialog.setVisible(false);
            }
        }).start();

        srv.start();

        srv.join();
    } catch (Exception e) {
        log.error("Error launching server: " + e.getMessage(), e);
    }
}

From source file:Main.java

static public JDialog addDialogWindow(Frame mainWindow, Component jpanel, String title) {
    JDialog dialog = new JDialog(mainWindow, title, true);
    dialog.getContentPane().setLayout(new BorderLayout());
    dialog.getContentPane().add(jpanel, BorderLayout.CENTER);
    dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
    dialog.pack();//from   ww w.j a  v  a 2 s. c  om
    dialog.setLocationRelativeTo(mainWindow);
    dialog.setSize(jpanel.getPreferredSize());
    dialog.setVisible(true);
    return dialog;
}

From source file:Main.java

static public JDialog addModelessWindow(Frame mainWindow, Component jpanel, String title) {
    JDialog dialog = new JDialog(mainWindow, title, true);
    dialog.getContentPane().setLayout(new BorderLayout());
    dialog.getContentPane().add(jpanel, BorderLayout.CENTER);
    dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
    dialog.pack();/*from   w  ww.  jav  a  2  s .  co  m*/
    dialog.setLocationRelativeTo(mainWindow);
    dialog.setModalityType(ModalityType.MODELESS);
    dialog.setSize(jpanel.getPreferredSize());
    dialog.setVisible(true);
    return dialog;
}

From source file:Main.java

public static void openDialogNextToParent(final JComponent parentComponent, final JDialog dialog) {
    SwingUtilities.invokeLater(new Runnable() {
        @Override/*from w  ww.  j a v  a2  s. c om*/
        public void run() {
            if (parentComponent != null) {
                Point parentLocation = parentComponent.getLocationOnScreen();
                parentLocation.x += parentComponent.getWidth();
                dialog.setLocation(parentLocation);
            }
            dialog.setVisible(true);
            dialog.setSize(dialog.getPreferredSize());
        }
    });
}

From source file:Main.java

public static void ensureMinimumSize(JDialog dialog, Dimension size) {
    Dimension s = dialog.getSize();
    Rectangle screen = availableScreenSize();

    if (s.width <= screen.width * 0.15 || s.height <= screen.height * 0.15) {
        // if the window as dimension less than 15% in some direction
        // increase it
        if (size == null) {
            Dimension m = new Dimension((int) (screen.width * 0.625), (int) (screen.height * 0.708));
            dialog.setSize(m);
        } else {//from ww w .ja  v a 2 s  .  co m

            Dimension m = new Dimension(Math.max(s.width, size.width), Math.max(s.height, size.height));
            dialog.setSize(m);
        }
    }

}

From source file:Main.java

static public JDialog addModelessWindow(Window mainWindow, Component jpanel, String title) {
    JDialog dialog;
    if (mainWindow != null) {
        dialog = new JDialog(mainWindow, title);
    } else {/*from  w  w w.  j ava  2s. c om*/
        dialog = new JDialog();
        dialog.setTitle(title);
    }
    dialog.getContentPane().setLayout(new BorderLayout());
    dialog.getContentPane().add(jpanel, BorderLayout.CENTER);
    dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
    dialog.pack();
    dialog.setLocationRelativeTo(mainWindow);
    dialog.setModalityType(ModalityType.MODELESS);
    dialog.setSize(jpanel.getPreferredSize());
    dialog.setVisible(true);
    return dialog;
}

From source file:Main.java

public Main() {
    setDefaultCloseOperation(EXIT_ON_CLOSE);
    JButton openDialog = new JButton("Click here");
    JPanel myPanel = new JPanel();
    myPanel.add(new JButton(new AbstractAction("Click here") {
        @Override/*from   w  w w  .jav  a 2s.  c om*/
        public void actionPerformed(ActionEvent e) {
            JDialog dialog = new JDialog(myFrame, true);
            JTextField myField = new JTextField(10);
            JPanel innerPanel = new JPanel();
            innerPanel.add(myField);
            dialog.add(innerPanel);
            dialog.pack();
            dialog.setSize(new Dimension(160, 120));
            dialog.setLocationRelativeTo(myFrame);
            dialog.setVisible(true);
        }
    }));
    add(myPanel);
    pack();
    setSize(new Dimension(320, 240));
    setLocationRelativeTo(null);
    setVisible(true);
}

From source file:com.aw.swing.mvp.JDialogView.java

public void unHide() {
    JDialog dlg = (JDialog) parentContainer;
    dlg.setSize(size);
    dlg.toFront();
}