List of usage examples for javax.swing JDialog pack
@SuppressWarnings("deprecation") public void pack()
From source file:Main.java
public static boolean showModalDialogOnEDT(JComponent contents, String title, String okButtonMessage, String cancelButtonMessage, ModalityType modalityType, final boolean systemExitOnDisposed) { class Result { boolean OK = false; }/*from www. j a v a2s.c o m*/ final Result result = new Result(); final JDialog dialog = new JDialog((Frame) null, title, true) { @Override public void dispose() { super.dispose(); if (systemExitOnDisposed) { System.exit(0); } } }; // ensure it doesn't block other dialogs if (modalityType != null) { dialog.setModalityType(modalityType); } // See http://stackoverflow.com/questions/1343542/how-do-i-close-a-jdialog-and-have-the-window-event-listeners-be-notified dialog.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); JPanel buttonPane = new JPanel(); buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT)); if (okButtonMessage != null) { buttonPane.add(new JButton(new AbstractAction(okButtonMessage) { @Override public void actionPerformed(ActionEvent e) { result.OK = true; dialog.dispose(); } })); } if (cancelButtonMessage != null) { buttonPane.add(new JButton(new AbstractAction(cancelButtonMessage) { @Override public void actionPerformed(ActionEvent e) { dialog.dispose(); } })); } JPanel panel = new JPanel(); panel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); panel.setLayout(new BorderLayout()); panel.add(contents, BorderLayout.CENTER); panel.add(buttonPane, BorderLayout.SOUTH); // startup frame dialog.getContentPane().add(panel); dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); dialog.pack(); // This hopefully centres the dialog even though the parameter is null // see http://stackoverflow.com/questions/213266/how-do-i-center-a-jdialog-on-screen dialog.setLocationRelativeTo(null); dialog.setVisible(true); return result.OK; }
From source file:com.sshtools.common.ui.OptionsPanel.java
/** * * * @param parent//from ww w. ja va 2s . co m * @param tabs tabs * * @return */ public static boolean showOptionsDialog(Component parent, OptionsTab[] tabs) { final OptionsPanel opts = new OptionsPanel(tabs); opts.reset(); JDialog d = null; Window w = (Window) SwingUtilities.getAncestorOfClass(Window.class, parent); if (w instanceof JDialog) { d = new JDialog((JDialog) w, "Options", true); } else if (w instanceof JFrame) { d = new JDialog((JFrame) w, "Options", true); } else { d = new JDialog((JFrame) null, "Options", true); } final JDialog dialog = d; // Create the bottom button panel final JButton cancel = new JButton("Cancel"); cancel.setMnemonic('c'); cancel.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { opts.cancelled = true; dialog.setVisible(false); } }); final JButton ok = new JButton("Ok"); ok.setMnemonic('o'); ok.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { if (opts.validateTabs()) { dialog.setVisible(false); } } }); dialog.getRootPane().setDefaultButton(ok); JPanel buttonPanel = new JPanel(new GridBagLayout()); GridBagConstraints gbc = new GridBagConstraints(); gbc.fill = GridBagConstraints.HORIZONTAL; gbc.anchor = GridBagConstraints.CENTER; gbc.insets = new Insets(6, 6, 0, 0); gbc.weighty = 1.0; UIUtil.jGridBagAdd(buttonPanel, ok, gbc, GridBagConstraints.RELATIVE); UIUtil.jGridBagAdd(buttonPanel, cancel, gbc, GridBagConstraints.REMAINDER); JPanel southPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT, 0, 0)); southPanel.add(buttonPanel); // JPanel mainPanel = new JPanel(new BorderLayout()); mainPanel.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4)); mainPanel.add(opts, BorderLayout.CENTER); mainPanel.add(southPanel, BorderLayout.SOUTH); // Show the dialog dialog.getContentPane().setLayout(new GridLayout(1, 1)); dialog.getContentPane().add(mainPanel); dialog.pack(); dialog.setResizable(true); UIUtil.positionComponent(SwingConstants.CENTER, dialog); dialog.setVisible(true); if (!opts.cancelled) { opts.applyTabs(); } return !opts.cancelled; }
From source file:fll.subjective.SubjectiveFrame.java
/** * Show differences./*from ww w. j a v a2 s. co m*/ */ private void showDifferencesDialog(final Collection<SubjectiveScoreDifference> diffs) { final SubjectiveDiffTableModel model = new SubjectiveDiffTableModel(diffs); final JTable table = new JTable(model); table.setGridColor(Color.BLACK); table.addMouseListener(new MouseAdapter() { public void mouseClicked(final MouseEvent e) { if (e.getClickCount() == 2) { final JTable target = (JTable) e.getSource(); final int row = target.getSelectedRow(); final SubjectiveScoreDifference diff = model.getDiffForRow(row); // find correct table final String category = diff.getCategory(); final JTable scoreTable = getTableForTitle(category); final int tabIndex = getTabIndexForCategory(category); getTabbedPane().setSelectedIndex(tabIndex); // get correct row and column final SubjectiveTableModel model = (SubjectiveTableModel) scoreTable.getModel(); final int scoreRow = model.getRowForTeamAndJudge(diff.getTeamNumber(), diff.getJudge()); final int scoreCol = model.getColForSubcategory(diff.getSubcategory()); if (scoreRow == -1 || scoreCol == -1) { throw new FLLRuntimeException( "Internal error: Cannot find correct row and column for score difference: " + diff); } scoreTable.changeSelection(scoreRow, scoreCol, false, false); } } }); final JDialog dialog = new JDialog(this, false); final Container cpane = dialog.getContentPane(); cpane.setLayout(new BorderLayout()); final JScrollPane tableScroller = new JScrollPane(table); cpane.add(tableScroller, BorderLayout.CENTER); dialog.pack(); dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); dialog.setVisible(true); }
From source file:com.brainflow.application.toplevel.Brainflow.java
private void initExceptionHandler() { LookAndFeelFactory.UIDefaultsCustomizer uiDefaultsCustomizer = new LookAndFeelFactory.UIDefaultsCustomizer() { public void customize(UIDefaults defaults) { ThemePainter painter = (ThemePainter) UIDefaultsLookup.get("Theme.painter"); defaults.put("OptionPaneUI", "com.jidesoft.plaf.basic.BasicJideOptionPaneUI"); defaults.put("OptionPane.showBanner", Boolean.TRUE); // show banner or not. default is true //defaults.put("OptionPane.bannerIcon", JideIconsFactory.getImageIcon(JideIconsFactory.JIDE50)); defaults.put("OptionPane.bannerFontSize", 13); defaults.put("OptionPane.bannerFontStyle", Font.BOLD); defaults.put("OptionPane.bannerMaxCharsPerLine", 60); defaults.put("OptionPane.bannerForeground", painter != null ? painter.getOptionPaneBannerForeground() : null); // you should adjust this if banner background is not the default gradient paint defaults.put("OptionPane.bannerBorder", null); // use default border // set both bannerBackgroundDk and // set both bannerBackgroundLt to null if you don't want gradient defaults.put("OptionPane.bannerBackgroundDk", painter != null ? painter.getOptionPaneBannerDk() : null); defaults.put("OptionPane.bannerBackgroundLt", painter != null ? painter.getOptionPaneBannerLt() : null); defaults.put("OptionPane.bannerBackgroundDirection", Boolean.TRUE); // default is true // optionally, you can set a Paint object for BannerPanel. If so, the three UIDefaults related to banner background above will be ignored. defaults.put("OptionPane.bannerBackgroundPaint", null); defaults.put("OptionPane.buttonAreaBorder", BorderFactory.createEmptyBorder(6, 6, 6, 6)); defaults.put("OptionPane.buttonOrientation", SwingConstants.RIGHT); }// www .jav a 2s. c o m }; uiDefaultsCustomizer.customize(UIManager.getDefaults()); Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { public void uncaughtException(Thread t, Throwable e) { e.printStackTrace(); JideOptionPane optionPane = new JideOptionPane( "Click \"Details\" button to see more information ... ", JOptionPane.ERROR_MESSAGE, JideOptionPane.CLOSE_OPTION); optionPane.setTitle("An " + e.getClass().getName() + " occurred in Brainflow : " + e.getMessage()); JTextArea textArea = new JTextArea(); StringWriter sw = new StringWriter(); PrintWriter out = new PrintWriter(sw); e.printStackTrace(out); // Add string to end of text area textArea.append(sw.toString()); textArea.setRows(10); optionPane.setDetails(new JScrollPane(textArea)); JDialog dialog = optionPane.createDialog(brainFrame, "Warning"); dialog.setResizable(true); dialog.pack(); dialog.setVisible(true); } }); }
From source file:IHM.GialogGraph.java
public void Show() { VisualizationViewer<String, String> vv; vv = new VisualizationViewer<>(new CircleLayout<String, String>(JungGraph), dim); Transformer<String, String> transformer = new Transformer<String, String>() { @Override// ww w.ja v a2s .c o m public String transform(String arg0) { return arg0; } }; vv.getRenderContext().setVertexLabelTransformer(transformer); transformer = new Transformer<String, String>() { @Override public String transform(String arg0) { return arg0; } }; vv.getRenderContext().setEdgeLabelTransformer(transformer); vv.getRenderer().setVertexRenderer(new MyRenderer()); DefaultModalGraphMouse<String, Number> graphMouse = new DefaultModalGraphMouse<String, Number>(); vv.setGraphMouse(graphMouse); graphMouse.setMode(ModalGraphMouse.Mode.PICKING); JDialog frame = new JDialog(MymainWidow); frame.getContentPane().add(vv); frame.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); frame.addWindowListener(new WindowListener() { @Override public void windowOpened(WindowEvent e) { } @Override public void windowClosing(WindowEvent e) { MymainWidow.enable(); } @Override public void windowClosed(WindowEvent e) { MymainWidow.enable(); } @Override public void windowIconified(WindowEvent e) { } @Override public void windowDeiconified(WindowEvent e) { } @Override public void windowActivated(WindowEvent e) { } @Override public void windowDeactivated(WindowEvent e) { } }); frame.pack(); frame.setLocationRelativeTo(MymainWidow); frame.setResizable(true); frame.setVisible(true); }
From source file:fr.duminy.components.swing.form.JFormPane.java
/** * Display this form in a dialog.//from w w w. j av a2 s . c o m * * @param parentComponent The parent component of the dialog. * @return The final value entered by the user in the dialog, or null if it was cancelled. */ public B showDialog(Component parentComponent) { Window parentWindow; if (parentComponent == null) { parentWindow = JOptionPane.getRootFrame(); } else if (parentComponent instanceof Window) { parentWindow = (Window) parentComponent; } else { parentWindow = SwingUtilities.getWindowAncestor(parentComponent); } final JDialog dialog = new JDialog(parentWindow, title, Dialog.ModalityType.APPLICATION_MODAL); dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); dialog.setContentPane(this); dialog.setResizable(false); setBorder(null); final MutableObject<Boolean> validated = new MutableObject<>(false); FormListener<B> listener = new FormListener<B>() { @Override public void formValidated(Form<B> form) { validated.setValue(true); dialog.dispose(); } @Override public void formCancelled(Form<B> form) { dialog.dispose(); } }; try { addFormListener(listener); dialog.pack(); dialog.setVisible(true); return validated.getValue() ? getValue() : null; } finally { removeFormListener(listener); } }
From source file:net.sourceforge.processdash.ev.ui.ScheduleBalancingDialog.java
private void buildAndShowGUI() { chartData = null;/*w ww . j a v a 2 s . c o m*/ int numScheduleRows = scheduleRows.size(); sumUpTotalTime(); originalTotalTime = totalRow.time; if (originalTotalTime == 0) // if the rows added up to zero, choose a nominal target total time // corresponding to 10 hours per included schedule originalTotalTime = numScheduleRows * 60 * 10; JPanel panel = new JPanel(new GridBagLayout()); if (numScheduleRows == 1) { totalRow.rowLabel = scheduleRows.get(0).rowLabel; } else { for (int i = 0; i < numScheduleRows; i++) scheduleRows.get(i).addToPanel(panel, i); scheduleRows.get(numScheduleRows - 1).showPercentageTickMarks(); addChartToPanel(panel, numScheduleRows + 1); } totalRow.addToPanel(panel, numScheduleRows); if (rowsAreEditable == false) { String title = TaskScheduleDialog.resources.getString("Balance.Read_Only_Title"); JOptionPane.showMessageDialog(parent.frame, panel, title, JOptionPane.PLAIN_MESSAGE); } else { String title = TaskScheduleDialog.resources.getString("Balance.Editable_Title"); JDialog dialog = new JDialog(parent.frame, title, true); addButtons(dialog, panel, numScheduleRows + 2); panel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); dialog.getContentPane().add(panel); dialog.pack(); dialog.setLocationRelativeTo(parent.frame); dialog.setResizable(true); dialog.setVisible(true); } }
From source file:de.codesourcery.gittimelapse.MyFrame.java
public MyFrame(File file, GitHelper gitHelper) throws RevisionSyntaxException, MissingObjectException, IncorrectObjectTypeException, AmbiguousObjectException, IOException, GitAPIException { super("GIT timelapse: " + file.getAbsolutePath()); if (gitHelper == null) { throw new IllegalArgumentException("gitHelper must not be NULL"); }/*from w w w . jav a 2 s .c o m*/ this.gitHelper = gitHelper; this.file = file; this.diffPanel = new DiffPanel(); final JDialog dialog = new JDialog((Frame) null, "Please wait...", false); dialog.getContentPane().setLayout(new BorderLayout()); dialog.getContentPane().add(new JLabel("Please wait, locating revisions..."), BorderLayout.CENTER); dialog.pack(); dialog.setVisible(true); final IProgressCallback callback = new IProgressCallback() { @Override public void foundCommit(ObjectId commitId) { System.out.println("*** Found commit " + commitId); } }; System.out.println("Locating commits..."); commitList = gitHelper.findCommits(file, callback); dialog.setVisible(false); if (commitList.isEmpty()) { throw new RuntimeException("Found no commits"); } setMenuBar(createMenuBar()); diffModeChooser.setModel(new DefaultComboBoxModel<MyFrame.DiffDisplayMode>(DiffDisplayMode.values())); diffModeChooser.setSelectedItem(DiffDisplayMode.ALIGN_CHANGES); diffModeChooser.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { final ObjectId commit = commitList.getCommit(revisionSlider.getValue() - 1); try { diffPanel.showRevision(commit); } catch (IOException | PatchApplyException e1) { e1.printStackTrace(); } } }); diffModeChooser.setRenderer(new DefaultListCellRenderer() { @Override public Component getListCellRendererComponent(JList<?> list, Object value, int index, boolean isSelected, boolean cellHasFocus) { Component result = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); DiffDisplayMode mode = (DiffDisplayMode) value; switch (mode) { case ALIGN_CHANGES: setText("Align changes"); break; case REGULAR: setText("Regular"); break; default: setText(mode.toString()); } return result; } }); revisionSlider = new JSlider(1, commitList.size()); revisionSlider.setPaintLabels(true); revisionSlider.setPaintTicks(true); addKeyListener(keyListener); getContentPane().addKeyListener(keyListener); if (commitList.size() < 10) { revisionSlider.setMajorTickSpacing(1); revisionSlider.setMinorTickSpacing(1); } else { revisionSlider.setMajorTickSpacing(5); revisionSlider.setMinorTickSpacing(1); } final ObjectId latestCommit = commitList.getLatestCommit(); if (latestCommit != null) { revisionSlider.setValue(1 + commitList.indexOf(latestCommit)); revisionSlider.setToolTipText(latestCommit.getName()); } revisionSlider.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { if (!revisionSlider.getValueIsAdjusting()) { final ObjectId commit = commitList.getCommit(revisionSlider.getValue() - 1); long time = -System.currentTimeMillis(); try { diffPanel.showRevision(commit); } catch (IOException | PatchApplyException e1) { e1.printStackTrace(); } finally { time += System.currentTimeMillis(); } if (Main.DEBUG_MODE) { System.out.println("Rendering time: " + time); } } } }); getContentPane().setLayout(new GridBagLayout()); GridBagConstraints cnstrs = new GridBagConstraints(); cnstrs.gridx = 0; cnstrs.gridy = 0; cnstrs.gridwidth = 1; cnstrs.gridheight = 1; cnstrs.weightx = 0; cnstrs.weighty = 0; cnstrs.fill = GridBagConstraints.NONE; getContentPane().add(new JLabel("Diff display mode:"), cnstrs); cnstrs = new GridBagConstraints(); cnstrs.gridx = 1; cnstrs.gridy = 0; cnstrs.gridwidth = 1; cnstrs.gridheight = 1; cnstrs.weightx = 0; cnstrs.weighty = 0; cnstrs.fill = GridBagConstraints.NONE; getContentPane().add(diffModeChooser, cnstrs); cnstrs = new GridBagConstraints(); cnstrs.gridx = 2; cnstrs.gridy = 0; cnstrs.gridwidth = 1; cnstrs.gridheight = 1; cnstrs.weightx = 1.0; cnstrs.weighty = 0; cnstrs.fill = GridBagConstraints.HORIZONTAL; getContentPane().add(revisionSlider, cnstrs); cnstrs = new GridBagConstraints(); cnstrs.gridx = 0; cnstrs.gridy = 1; cnstrs.gridwidth = 3; cnstrs.gridheight = 1; cnstrs.weightx = 1; cnstrs.weighty = 1; cnstrs.fill = GridBagConstraints.BOTH; getContentPane().add(diffPanel, cnstrs); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); if (latestCommit != null) { diffPanel.showRevision(latestCommit); } }
From source file:eu.delving.sip.Application.java
private static void memoryNotConfigured() { String os = System.getProperty("os.name"); Runtime rt = Runtime.getRuntime(); int totalMemory = (int) (rt.totalMemory() / 1024 / 1024); StringBuilder out = new StringBuilder(); String JAR_NAME = "SIP-Creator-2014-XX-XX.jar"; if (os.startsWith("Windows")) { out.append(":: SIP-Creator Startup Batch file for Windows (more memory than ").append(totalMemory) .append("Mb)\n"); out.append("java -jar -Xms1024m -Xmx1024m ").append(JAR_NAME); } else if (os.startsWith("Mac")) { out.append("# SIP-Creator Startup Script for Mac OSX (more memory than ").append(totalMemory) .append("Mb)\n"); out.append("java -jar -Xms1024m -Xmx1024m ").append(JAR_NAME); } else {/*from www .j a va 2 s .co m*/ System.out.println("Unrecognized OS: " + os); } String script = out.toString(); final JDialog dialog = new JDialog(null, "Memory Not Configured Yet!", Dialog.ModalityType.APPLICATION_MODAL); JTextArea scriptArea = new JTextArea(3, 40); scriptArea.setText(script); scriptArea.setSelectionStart(0); scriptArea.setSelectionEnd(script.length()); JPanel scriptPanel = new JPanel(new BorderLayout()); scriptPanel.setBorder(BorderFactory.createTitledBorder("Script File")); scriptPanel.add(scriptArea, BorderLayout.CENTER); JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT)); buttonPanel.setBorder(BorderFactory.createEmptyBorder(15, 15, 15, 15)); JButton ok = new JButton("OK, Continue anyway"); ok.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { dialog.setVisible(false); EventQueue.invokeLater(LAUNCH); } }); buttonPanel.add(ok); JPanel centralPanel = new JPanel(new GridLayout(0, 1)); centralPanel.setBorder(BorderFactory.createEmptyBorder(15, 25, 15, 25)); centralPanel.add( new JLabel("<html><b>The SIP-Creator started directly can have too little default memory allocated." + "<br>It should be started with the following script:</b>")); centralPanel.add(scriptPanel); centralPanel.add(new JLabel( "<html><b>Please copy the above text into a batch or script file and execute that instead.</b>")); dialog.getContentPane().add(centralPanel, BorderLayout.CENTER); dialog.getContentPane().add(buttonPanel, BorderLayout.SOUTH); dialog.pack(); Dimension dimension = Toolkit.getDefaultToolkit().getScreenSize(); int x = (int) ((dimension.getWidth() - dialog.getWidth()) / 2); int y = (int) ((dimension.getHeight() - dialog.getHeight()) / 2); dialog.setLocation(x, y); dialog.setVisible(true); }
From source file:de.tudarmstadt.ukp.clarin.webanno.webapp.standalone.StandaloneShutdownDialog.java
private void displayShutdownDialog() { String serverId = ServerDetector.getServerId(); log.info("Running in: " + (serverId != null ? serverId : "unknown server")); log.info("Console: " + ((System.console() != null) ? "available" : "not available")); log.info("Headless: " + (GraphicsEnvironment.isHeadless() ? "yes" : "no")); // Show this only when run from the standalone JAR via a double-click if (System.console() == null && !GraphicsEnvironment.isHeadless() && ServerDetector.isWinstone()) { log.info("If you are running WebAnno in a server environment, please use '-Djava.awt.headless=true'"); EventQueue.invokeLater(new Runnable() { @Override/*w w w . j a v a 2 s . c o m*/ public void run() { final JOptionPane optionPane = new JOptionPane(new JLabel( "<HTML>WebAnno is running now and can be accessed via <a href=\"http://localhost:8080\">http://localhost:8080</a>.<br>" + "WebAnno works best with the browsers Google Chrome or Safari.<br>" + "Use this dialog to shut WebAnno down.</HTML>"), JOptionPane.INFORMATION_MESSAGE, JOptionPane.OK_OPTION, null, new String[] { "Shutdown" }); final JDialog dialog = new JDialog((JFrame) null, "WebAnno", true); dialog.setContentPane(optionPane); dialog.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE); dialog.addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent we) { // Avoid closing window by other means than button } }); optionPane.addPropertyChangeListener(new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent aEvt) { if (dialog.isVisible() && (aEvt.getSource() == optionPane) && (aEvt.getPropertyName().equals(JOptionPane.VALUE_PROPERTY))) { System.exit(0); } } }); dialog.pack(); dialog.setVisible(true); } }); } else { log.info("Running in server environment or from command line: disabling interactive shutdown dialog."); } }