List of usage examples for javax.swing JDialog pack
@SuppressWarnings("deprecation") public void pack()
From source file:Main.java
public static void showDialog(JDialog dlg, Component parent, boolean resizable) { dlg.setResizable(resizable);//from ww w. j a v a 2s .c o m dlg.pack(); dlg.setLocationRelativeTo(parent); dlg.setVisible(true); }
From source file:Main.java
/** * JOption panes static methods are not swing-conform and not decoratable. * <p>//w ww . j a v a2 s . c o m * This utility function corrects this by giving the dialog/rootPane the name "Synth.Dialog" */ public static void showMessageDialogSynthCapable(Component parentComponent, Object message, String title, int messageType) { JOptionPane pane = new JOptionPane(message, messageType); JDialog dlg = pane.createDialog(parentComponent, title); dlg.getRootPane().setName("Synth.Dialog"); dlg.pack(); dlg.setVisible(true); }
From source file:Main.java
public static void showModalDialog(JDialog dlg, Component parent, boolean resizable) { dlg.setResizable(resizable);/*from www.j ava2 s. c o m*/ dlg.setModal(true); dlg.pack(); dlg.setLocationRelativeTo(parent); dlg.setVisible(true); }
From source file:Main.java
private static JButton newButton(String label) { final JButton button = new JButton(label); button.addActionListener(e -> {/*from w w w . j av a 2 s .co m*/ Window parentWindow = SwingUtilities.windowForComponent(button); JDialog dialog = new JDialog(parentWindow); dialog.setLocationRelativeTo(button); dialog.setModal(true); dialog.add(newPane("Label")); dialog.pack(); dialog.setVisible(true); }); return button; }
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(); dialog.setLocationRelativeTo(mainWindow); dialog.setSize(jpanel.getPreferredSize()); dialog.setVisible(true);/*from www. j a v a 2s.co m*/ 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(); dialog.setLocationRelativeTo(mainWindow); dialog.setModalityType(ModalityType.MODELESS); dialog.setSize(jpanel.getPreferredSize()); dialog.setVisible(true);/*from w w w . ja va 2 s . c o m*/ return dialog; }
From source file:net.redstonelamp.gui.RedstoneLampGUI.java
private static void installCallback(JFrame frame, File selected) { JDialog dialog = new JDialog(frame); JLabel status = new JLabel("Downloading build..."); JProgressBar progress = new JProgressBar(); dialog.pack(); dialog.setVisible(true);/*from www. ja va2s . c o m*/ try { URL url = new URL("http://download.redstonelamp.net/?file=LatestBuild"); InputStream is = url.openStream(); int size = is.available(); progress.setMinimum(0); progress.setMaximum(size); int size2 = size; OutputStream os = new FileOutputStream(new File(selected, "RedstoneLamp.jar")); while (size2 > 0) { int length = Math.min(4096, size2); byte[] buffer = new byte[length]; size2 -= length; is.read(buffer); progress.setValue(size2); os.write(buffer); } is.close(); os.close(); } catch (IOException e) { e.printStackTrace(); } }
From source file:Main.java
/** * Displays the given file chooser. Utility method for avoiding of memory leak in JDK * 1.3 {@link javax.swing.JFileChooser#showDialog}. * * @param chooser the file chooser to display. * @param parent the parent window./* w w w .jav a 2 s . co m*/ * @param approveButtonText the text for the approve button. * * @return the return code of the chooser. */ public static final int showJFileChooser(JFileChooser chooser, Component parent, String approveButtonText) { if (approveButtonText != null) { chooser.setApproveButtonText(approveButtonText); chooser.setDialogType(javax.swing.JFileChooser.CUSTOM_DIALOG); } Frame frame = (parent instanceof Frame) ? (Frame) parent : (Frame) javax.swing.SwingUtilities.getAncestorOfClass(java.awt.Frame.class, parent); String title = chooser.getDialogTitle(); if (title == null) { title = chooser.getUI().getDialogTitle(chooser); } final JDialog dialog = new JDialog(frame, title, true); dialog.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); Container contentPane = dialog.getContentPane(); contentPane.setLayout(new BorderLayout()); contentPane.add(chooser, BorderLayout.CENTER); dialog.pack(); dialog.setLocationRelativeTo(parent); chooser.rescanCurrentDirectory(); final int[] retValue = new int[] { javax.swing.JFileChooser.CANCEL_OPTION }; ActionListener l = new ActionListener() { public void actionPerformed(ActionEvent ev) { if (ev.getActionCommand() == JFileChooser.APPROVE_SELECTION) { retValue[0] = JFileChooser.APPROVE_OPTION; } dialog.setVisible(false); dialog.dispose(); } }; chooser.addActionListener(l); dialog.show(); return (retValue[0]); }
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 a va2 s .co m*/ 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:de.ipk_gatersleben.ag_nw.graffiti.services.GUIhelper.java
public static JComponent getWebsiteDownloadButton(final String title, final String optUrlManualDownloadWebsite, final String target_dir_null_ask_user, final String optIntroText, final String[] downloadURLs, final String optIntroDialogTitle, final FileDownloadStatusInformationProvider statusProvider, final Runnable optFinishSwingTask) { final JButton res = new JMButton("Download/Update"); res.setToolTipText(//from www . j a v a 2s .com "<html>Click button to start automatic download<br><code><b>Check License/Disclaimers first!"); res.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { final String opt_local_folder; if (target_dir_null_ask_user == null) { File file = OpenFileDialogService.getDirectoryFromUser("Select folder"); if (file == null) return; else opt_local_folder = file.getAbsolutePath(); } else { opt_local_folder = target_dir_null_ask_user; } res.setEnabled(false); res.setText("Downloading"); final BackgroundTaskStatusProviderSupportingExternalCallImpl status = new BackgroundTaskStatusProviderSupportingExternalCallImpl( "Please wait...", "Downloading files..."); BackgroundTaskHelper.issueSimpleTask(title, "Please wait...", new Runnable() { public void run() { boolean allOK = true; for (String downloadURL : downloadURLs) { allOK = performDownload(downloadURL, opt_local_folder, status); if (status.wantsToStop()) { break; } } if (status.wantsToStop()) { allOK = true; try { status.setCurrentStatusText1("Cancel..."); for (String downloadURL : downloadURLs) { String fileName = downloadURL.substring(downloadURL.lastIndexOf("/") + 1); if (downloadURL.contains("|")) fileName = downloadURL.substring(downloadURL.lastIndexOf("|") + 1); String targetFileName = ReleaseInfo.getAppFolderWithFinalSep() + fileName; if (new File(targetFileName).exists()) { new File(targetFileName).delete(); status.setCurrentStatusText2("Delete " + targetFileName); } } } catch (Exception e) { // } } if (!allOK) { res.setEnabled(true); res.setText( "<html><small>Automatic download failure<br>Click here for manual download"); res.removeActionListener(res.getActionListeners()[0]); res.addActionListener(getDialogAction(optUrlManualDownloadWebsite, opt_local_folder, optIntroText, optIntroDialogTitle)); res.requestFocus(); final JDialog jd = (JDialog) ErrorMsg.findParentComponent(res, JDialog.class); if (jd != null) { SwingUtilities.invokeLater(new Runnable() { public void run() { jd.pack(); } }); } } else { if (status.wantsToStop()) { res.setText("Canceled"); status.pleaseContinueRun(); status.setCurrentStatusText2("Canceled!"); } else { res.setText("Downloaded"); } res.setEnabled(false); if (statusProvider != null) statusProvider.finishedNewDownload(); if (optFinishSwingTask != null) SwingUtilities.invokeLater(optFinishSwingTask); } } }, null, status); } }); return res; }