List of usage examples for javax.swing JOptionPane showOptionDialog
@SuppressWarnings("deprecation") public static int showOptionDialog(Component parentComponent, Object message, String title, int optionType, int messageType, Icon icon, Object[] options, Object initialValue) throws HeadlessException
initialValue
parameter and the number of choices is determined by the optionType
parameter. From source file:VoteDialog.java
private JPanel createSimpleDialogBox() { final int numButtons = 4; JRadioButton[] radioButtons = new JRadioButton[numButtons]; final ButtonGroup group = new ButtonGroup(); JButton voteButton = null;//from ww w.j a v a 2 s . c om final String defaultMessageCommand = "default"; final String yesNoCommand = "yesno"; final String yeahNahCommand = "yeahnah"; final String yncCommand = "ync"; radioButtons[0] = new JRadioButton("<html>Candidate 1: <font color=red>Sparky the Dog</font></html>"); radioButtons[0].setActionCommand(defaultMessageCommand); radioButtons[1] = new JRadioButton("<html>Candidate 2: <font color=green>Shady Sadie</font></html>"); radioButtons[1].setActionCommand(yesNoCommand); radioButtons[2] = new JRadioButton("<html>Candidate 3: <font color=blue>R.I.P. McDaniels</font></html>"); radioButtons[2].setActionCommand(yeahNahCommand); radioButtons[3] = new JRadioButton( "<html>Candidate 4: <font color=maroon>Duke the Java<font size=-2><sup>TM</sup></font size> Platform Mascot</font></html>"); radioButtons[3].setActionCommand(yncCommand); for (int i = 0; i < numButtons; i++) { group.add(radioButtons[i]); } // Select the first button by default. radioButtons[0].setSelected(true); voteButton = new JButton("Vote"); voteButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { String command = group.getSelection().getActionCommand(); // ok dialog if (command == defaultMessageCommand) { JOptionPane.showMessageDialog(frame, "This candidate is a dog. Invalid vote."); // yes/no dialog } else if (command == yesNoCommand) { int n = JOptionPane.showConfirmDialog(frame, "This candidate is a convicted felon. \nDo you still want to vote for her?", "A Follow-up Question", JOptionPane.YES_NO_OPTION); if (n == JOptionPane.YES_OPTION) { setLabel("OK. Keep an eye on your wallet."); } else if (n == JOptionPane.NO_OPTION) { setLabel("Whew! Good choice."); } else { setLabel("It is your civic duty to cast your vote."); } // yes/no (with customized wording) } else if (command == yeahNahCommand) { Object[] options = { "Yes, please", "No, thanks" }; int n = JOptionPane.showOptionDialog(frame, "This candidate is deceased. \nDo you still want to vote for him?", "A Follow-up Question", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[0]); if (n == JOptionPane.YES_OPTION) { setLabel("I hope you don't expect much from your candidate."); } else if (n == JOptionPane.NO_OPTION) { setLabel("Whew! Good choice."); } else { setLabel("It is your civic duty to cast your vote."); } // yes/no/cancel (with customized wording) } else if (command == yncCommand) { Object[] options = { "Yes!", "No, I'll pass", "Well, if I must" }; int n = JOptionPane.showOptionDialog(frame, "Duke is a cartoon mascot. \nDo you " + "still want to cast your vote?", "A Follow-up Question", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[2]); if (n == JOptionPane.YES_OPTION) { setLabel("Excellent choice."); } else if (n == JOptionPane.NO_OPTION) { setLabel("Whatever you say. It's your vote."); } else if (n == JOptionPane.CANCEL_OPTION) { setLabel("Well, I'm certainly not going to make you vote."); } else { setLabel("It is your civic duty to cast your vote."); } } return; } }); System.out.println("calling createPane"); return createPane(simpleDialogDesc + ":", radioButtons, voteButton); }
From source file:org.fhaes.FHRecorder.FireHistoryRecorder.java
/** * Closes the dialog but only after running necessary checks * to ensure user doesn't inadvertently loose data * /*from ww w . j ava2s .c om*/ */ private void closeAfterRunningChecks() { if (Controller.isModified()) { Object[] options = { "Save", "Close without saving", "Cancel" }; int n = JOptionPane.showOptionDialog(Controller.thePrimaryWindow, "Save changes to file before closing?", "Confirm", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[2]); if (n == JOptionPane.YES_OPTION) { Controller.save(); setVisible(false); } else if (n == JOptionPane.NO_OPTION) { Controller.setIsModified(false); Controller.setIsChangedSinceOpened(false); setVisible(false); } else if (n == JOptionPane.CANCEL_OPTION) { return; } } setVisible(false); }
From source file:net.pms.newgui.SelectRenderers.java
/** * Create the GUI and show it./* w ww . jav a 2 s. c o m*/ */ public void showDialog() { if (!init) { // Initial call build(); init = true; } SrvTree.validate(); // Refresh setting if modified selectedRenderers = configuration.getSelectedRenderers(); TreePath root = new TreePath(allRenderers); if (selectedRenderers.isEmpty() || (selectedRenderers.size() == 1 && selectedRenderers.get(0) == null)) { checkTreeManager.getSelectionModel().clearSelection(); } else if (selectedRenderers.size() == 1 && selectedRenderers.get(0).equals(allRenderersTreeName)) { checkTreeManager.getSelectionModel().setSelectionPath(root); } else { if (root.getLastPathComponent() instanceof SearchableMutableTreeNode) { SearchableMutableTreeNode rootNode = (SearchableMutableTreeNode) root.getLastPathComponent(); SearchableMutableTreeNode node = null; List<TreePath> selectedRenderersPath = new ArrayList<>(selectedRenderers.size()); for (String selectedRenderer : selectedRenderers) { try { node = rootNode.findInBranch(selectedRenderer, true); } catch (IllegalChildException e) { } if (node != null) { selectedRenderersPath.add(new TreePath(node.getPath())); } } checkTreeManager.getSelectionModel().setSelectionPaths( selectedRenderersPath.toArray(new TreePath[selectedRenderersPath.size()])); } else { LOGGER.error("Illegal node class in SelectRenderers.showDialog(): {}", root.getLastPathComponent().getClass().getSimpleName()); } } int selectRenderers = JOptionPane.showOptionDialog((Component) PMS.get().getFrame(), this, Messages.getString("GeneralTab.5"), JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE, null, null, null); if (selectRenderers == JOptionPane.OK_OPTION) { TreePath[] selected = checkTreeManager.getSelectionModel().getSelectionPaths(); if (selected.length == 0) { if (configuration.setSelectedRenderers("")) { PMS.get().getFrame().setReloadable(true); // notify the user to restart the server } } else if (selected.length == 1 && selected[0].getLastPathComponent() instanceof SearchableMutableTreeNode && ((SearchableMutableTreeNode) selected[0].getLastPathComponent()).getNodeName() .equals(allRenderers.getNodeName())) { if (configuration.setSelectedRenderers(allRenderersTreeName)) { PMS.get().getFrame().setReloadable(true); // notify the user to restart the server } } else { List<String> selectedRenderers = new ArrayList<>(); for (TreePath path : selected) { String rendererName = ""; if (path.getPathComponent(0).equals(allRenderers)) { for (int i = 1; i < path.getPathCount(); i++) { if (path.getPathComponent(i) instanceof SearchableMutableTreeNode) { if (!rendererName.isEmpty()) { rendererName += " "; } rendererName += ((SearchableMutableTreeNode) path.getPathComponent(i)) .getNodeName(); } else { LOGGER.error("Invalid tree node component class {}", path.getPathComponent(i).getClass().getSimpleName()); } } if (!rendererName.isEmpty()) { selectedRenderers.add(rendererName); } } else { LOGGER.warn("Invalid renderer treepath encountered: {}", path.toString()); } } if (configuration.setSelectedRenderers(selectedRenderers)) { PMS.get().getFrame().setReloadable(true); // notify the user to restart the server } } } }
From source file:com.sshtools.appframework.ui.SshToolsApplicationFrame.java
/** * @param application/*from ww w .j a va 2 s . c om*/ * @param panel * * @throws SshToolsApplicationException */ public void init(final SshToolsApplication application, SshToolsApplicationPanel panel) throws SshToolsApplicationException { log.debug("Initialising frame"); this.panel = panel; this.application = application; if (application != null) { setTitle(application.getApplicationName() + " - " + application.getApplicationVersion()); } setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); // Register the File menu panel.registerActionMenu(new ActionMenu("File", "File", 'f', 0)); // Register the Exit action if (showExitAction && application != null) { panel.registerAction(exitAction = new ExitAction(application, this)); // Register the New Window Action } if (showNewWindowAction && application != null) { panel.registerAction(newWindowAction = new NewWindowAction(application)); // Register the Help menu } panel.registerActionMenu(new ActionMenu("Help", "Help", 'h', 99)); // Register the About box action if (showAboutBox && application != null) { panel.registerAction(aboutAction = new AboutAction(this, application)); } getApplicationPanel().rebuildActionComponents(); // JPanel p = new JPanel(new ToolBarLayout()); JPanel p = new JPanel(new BorderLayout(0, 0)); JPanel center = new JPanel(new BorderLayout(0, 0)); if (panel.getJMenuBar() != null) { setJMenuBar(panel.getJMenuBar()); } if (panel.getToolBar() != null) { // center.add(toolSeparator = new JSeparator(JSeparator.HORIZONTAL), // BorderLayout.NORTH); // toolSeparator.setVisible(panel.getToolBar().isVisible()); // panel.getToolBar().addComponentListener(new ComponentAdapter() { // public void componentShown(ComponentEvent e) { // toolSeparator.setVisible(SshToolsApplicationFrame.this.panel.getToolBar().isVisible()); // } // // public void componentHidden(ComponentEvent e) { // toolSeparator.setVisible(SshToolsApplicationFrame.this.panel.getToolBar().isVisible()); // } // // }); final SshToolsApplicationPanel pnl = panel; panel.getToolBar().addComponentListener(new ComponentAdapter() { public void componentHidden(ComponentEvent evt) { // toolSeparator.setVisible(pnl.getToolBar().isVisible()); } }); p.add(panel.getToolBar(), BorderLayout.NORTH); } center.add(panel, BorderLayout.CENTER); p.add(center, BorderLayout.CENTER); getContentPane().setLayout(new GridLayout(1, 1, 0, 0)); getContentPane().add(p); // Watch for the frame closing setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent evt) { if (application != null) { application.closeContainer(SshToolsApplicationFrame.this); } else { int confirm = JOptionPane.showOptionDialog(SshToolsApplicationFrame.this, "Close " + getTitle() + "?", "Close Operation", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, null, null); if (confirm == 0) { hide(); } } } }); // If this is the first frame, center the window on the screen Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); boolean found = false; if (application != null && application.getContainerCount() != 0) { for (int i = 0; (i < application.getContainerCount()) && !found; i++) { SshToolsApplicationContainer c = application.getContainerAt(i); if (c instanceof SshToolsApplicationFrame) { SshToolsApplicationFrame f = (SshToolsApplicationFrame) c; setSize(f.getSize()); Point newLocation = new Point(f.getX(), f.getY()); newLocation.x += 48; newLocation.y += 48; if (newLocation.x > (screenSize.getWidth() - 64)) { newLocation.x = 0; } if (newLocation.y > (screenSize.getHeight() - 64)) { newLocation.y = 0; } setLocation(newLocation); found = true; } } } if (!found) { // Is there a previous stored geometry we can use? if (PreferencesStore.preferenceExists(PREF_LAST_FRAME_GEOMETRY)) { setBounds(PreferencesStore.getRectangle(PREF_LAST_FRAME_GEOMETRY, getBounds())); } else { pack(); setSize(800, 600); UIUtil.positionComponent(SwingConstants.CENTER, this); } } log.debug("Initialisation of frame complete"); }
From source file:components.IntegerEditor.java
/** * Lets the user know that the text they entered is * bad. Returns true if the user elects to revert to * the last good value. Otherwise, returns false, * indicating that the user wants to continue editing. *//*w w w . j a v a2 s .c om*/ protected boolean userSaysRevert() { Toolkit.getDefaultToolkit().beep(); ftf.selectAll(); Object[] options = { "Edit", "Revert" }; int answer = JOptionPane.showOptionDialog(SwingUtilities.getWindowAncestor(ftf), "The value must be an integer between " + minimum + " and " + maximum + ".\n" + "You can either continue editing " + "or revert to the last valid value.", "Invalid Text Entered", JOptionPane.YES_NO_OPTION, JOptionPane.ERROR_MESSAGE, null, options, options[1]); if (answer == 1) { //Revert! ftf.setValue(ftf.getValue()); return true; } return false; }
From source file:com.sec.ose.osi.ui.frm.main.report.JPanReportMain.java
private boolean checkIdentifyCompletion(String projectName) { if (IdentifyQueue.getInstance().isIdentifyCompleted(projectName) == true) { return true; }/*from w w w . j a v a 2s . c om*/ String[] buttonList = { "Yes", "No" }; int choice = JOptionPane.showOptionDialog(null, "Identify transactions for " + projectName + " are on updating.\n" + "You must wait for completing all transactions to obtain accurate report.\n" + "Are you sure to generate the report anyway?\n", "Warning", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE, null, buttonList, "Yes"); if (choice == JOptionPane.YES_OPTION) { return true; } return false; }
From source file:net.atomique.ksar.ui.GraphView.java
private String askSaveFilename(String title, File chdirto) { String filename = null;/*www . j a v a 2s.co m*/ JFileChooser chooser = new JFileChooser(); chooser.setDialogTitle(title); if (chdirto != null) { chooser.setCurrentDirectory(chdirto); } int returnVal = chooser.showSaveDialog(GlobalOptions.getUI()); if (returnVal == JFileChooser.APPROVE_OPTION) { filename = chooser.getSelectedFile().getAbsolutePath(); } if (filename == null) { return null; } if (new File(filename).exists()) { String[] choix = { "Yes", "No" }; int resultat = JOptionPane.showOptionDialog(null, "Overwrite " + filename + " ?", "File Exist", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, choix, choix[1]); if (resultat != 0) { return null; } } return filename; }
From source file:gov.nih.nci.nbia.StandaloneDMDispatcher.java
private void checkManifestVersion(String manifestVersion) { if ((manifestVersion != null) && (Double.valueOf(manifestVersion) > Double.valueOf(appVersion))) { Object[] options = { "OK" }; int n = JOptionPane.showOptionDialog(null, manifestVersionNewMsg, "Incompatible Manifest File Version Notification", JOptionPane.OK_OPTION, JOptionPane.INFORMATION_MESSAGE, null, options, options[0]); }/*from w ww. j a va 2 s . c om*/ if (((manifestVersion == null) && (supportedVersion != null)) || ((manifestVersion != null) && (supportedVersion != null) && (Double.valueOf(manifestVersion) < Double.valueOf(supportedVersion)))) { Object[] options = { "OK" }; int n = JOptionPane.showOptionDialog(null, manifestVersionMsg + appVersion + ".", "Incompatible Manifest File Version Notification", JOptionPane.OK_OPTION, JOptionPane.INFORMATION_MESSAGE, null, options, options[0]); System.exit(n); } }
From source file:de.dal33t.powerfolder.PowerFolder.java
/** * Starts a PowerFolder controller with the given command line arguments * * @param args//from w ww .j a v a 2s .c om */ public static void startPowerFolder(String[] args) { // Touch Logger immediately to initialize handlers. LoggingManager.isLogToFile(); // Default exception logger Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { public void uncaughtException(Thread t, Throwable e) { e.printStackTrace(); log.log(Level.SEVERE, "Exception in " + t + ": " + e.toString(), e); } }); CommandLine commandLine = parseCommandLine(args); if (commandLine == null) { return; } // -l --log console log levels (severe, warning, info, fine and finer). if (commandLine.hasOption("l")) { String levelName = commandLine.getOptionValue("l"); Level level = LoggingManager.levelForName(levelName); if (level != null) { LoggingManager.setConsoleLogging(level); } } if (commandLine.hasOption("s")) { // Server mode, suppress debug output on console // Logger.addExcludeConsoleLogLevel(Logger.DEBUG); } if (commandLine.hasOption("h")) { // Show help HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("PowerFolder", COMMAND_LINE_OPTIONS); return; } int rconPort = Integer.valueOf(ConfigurationEntry.NET_RCON_PORT.getDefaultValue()); String portStr = commandLine.getOptionValue("k"); if (StringUtils.isNotBlank(portStr)) { try { rconPort = Integer.valueOf(portStr.trim()); } catch (Exception e) { log.warning("Unable to parse rcon port: " + portStr + ". " + e); } } boolean runningInstanceFound = RemoteCommandManager.hasRunningInstance(rconPort); if (commandLine.hasOption("k")) { if (runningInstanceFound) { System.out.println("Stopping " + NAME); // Send quit command RemoteCommandManager.sendCommand(rconPort, RemoteCommandManager.QUIT); } else { System.err.println("Process not running"); } // stop return; } // set language from commandline to preferences if (commandLine.hasOption("g")) { Preferences.userNodeForPackage(Translation.class).put("locale", commandLine.getOptionValue("g")); } if (JavaVersion.systemVersion().isOpenJDK()) { Object[] options = { "Open Oracle home page and exit", "Exit" }; int n = JOptionPane.showOptionDialog(null, "You are using OpenJDK which is unsupported.\n" + "Please install the client with bundled JRE or install the Oracle JRE", "Unsupported JRE", JOptionPane.OK_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE, null, options, options[0]); if (n == 0) { try { BrowserLauncher.openURL("http://www.java.com"); } catch (IOException e1) { e1.printStackTrace(); } } return; } // The controller. Controller controller = Controller.createController(); String[] files = commandLine.getArgs(); // Parsing of command line completed boolean commandContainsRemoteCommands = files != null && files.length >= 1 || commandLine.hasOption("e") || commandLine.hasOption("r") || commandLine.hasOption("a"); // Try to start controller boolean startController = !commandContainsRemoteCommands || !runningInstanceFound; try { log.info("PowerFolder v" + Controller.PROGRAM_VERSION); // Start controller if (startController) { controller.startConfig(commandLine); } // Send remote command if there a files in commandline if (files != null && files.length > 0) { // Parse filenames and build remote command StringBuilder openFilesRCommand = new StringBuilder(RemoteCommandManager.OPEN); for (String file : files) { openFilesRCommand.append(file); // FIXME: Add ; separator ? } // Send remote command to running PowerFolder instance RemoteCommandManager.sendCommand(openFilesRCommand.toString()); } if (commandLine.hasOption("e")) { RemoteCommandManager.sendCommand(RemoteCommandManager.MAKEFOLDER + commandLine.getOptionValue("e")); } if (commandLine.hasOption("r")) { RemoteCommandManager .sendCommand(RemoteCommandManager.REMOVEFOLDER + commandLine.getOptionValue("r")); } if (commandLine.hasOption("a")) { RemoteCommandManager.sendCommand(RemoteCommandManager.COPYLINK + commandLine.getOptionValue("a")); } } catch (Throwable t) { t.printStackTrace(); log.log(Level.SEVERE, "Throwable", t); return; } // Begin monitoring memory usage. if (controller.isStarted() && controller.isUIEnabled()) { ScheduledExecutorService service = controller.getThreadPool(); service.scheduleAtFixedRate(new MemoryMonitor(controller), 1, 1, TimeUnit.MINUTES); } // Not go into console mode if ui is open if (!startController) { if (runningInstanceFound) { RemoteCommandManager.sendCommand(RemoteCommandManager.SHOW_UI); } return; } System.out.println("------------ " + NAME + " " + Controller.PROGRAM_VERSION + " started ------------"); boolean restartRequested = false; do { // Go into restart loop while (controller.isStarted() || controller.isShuttingDown()) { try { Thread.sleep(500); } catch (InterruptedException e) { log.log(Level.WARNING, "InterruptedException", e); return; } } restartRequested = controller.isRestartRequested(); if (restartRequested) { Map<Thread, StackTraceElement[]> threads = Thread.getAllStackTraces(); for (Thread thread : threads.keySet()) { if (thread.getName().startsWith("PoolThread") || thread.getName().startsWith("Reconnector") || thread.getName().startsWith("ConHandler")) { thread.interrupt(); } } log.info("Restarting controller"); System.out.println( "------------ " + NAME + " " + Controller.PROGRAM_VERSION + " restarting ------------"); controller = null; System.gc(); controller = Controller.createController(); // Start controller controller.startConfig(commandLine); } } while (restartRequested); }
From source file:com.sshtools.common.ui.SshToolsApplicationFrame.java
/** * * * @param application/*from w ww . ja v a 2 s . c om*/ * @param panel * * @throws SshToolsApplicationException */ public void init(final SshToolsApplication application, SshToolsApplicationPanel panel) throws SshToolsApplicationException { this.panel = panel; this.application = application; if (application != null) { setTitle(ConfigurationLoader.getVersionString(application.getApplicationName(), application.getApplicationVersion())); // + " " + application.getApplicationVersion()); } setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); // Register the File menu panel.registerActionMenu(new SshToolsApplicationPanel.ActionMenu("File", "File", 'f', 0)); // Register the Exit action if (showExitAction && application != null) { panel.registerAction(exitAction = new ExitAction(application, this)); // Register the New Window Action } if (showNewWindowAction && application != null) { panel.registerAction(newWindowAction = new NewWindowAction(application)); // Register the Help menu } panel.registerActionMenu(new SshToolsApplicationPanel.ActionMenu("Help", "Help", 'h', 99)); // Register the About box action if (showAboutBox && application != null) { panel.registerAction(aboutAction = new AboutAction(this, application)); } // Register the Changelog box action if (showChangelogBox && application != null) { panel.registerAction(changelogAction = new ChangelogAction(this, application)); } panel.registerAction(faqAction = new FAQAction()); panel.registerAction(beginnerAction = new BeginnerAction()); panel.registerAction(advancedAction = new AdvancedAction()); getApplicationPanel().rebuildActionComponents(); JPanel p = new JPanel(new BorderLayout()); if (panel.getJMenuBar() != null) { setJMenuBar(panel.getJMenuBar()); } if (panel.getToolBar() != null) { JPanel t = new JPanel(new BorderLayout()); t.add(panel.getToolBar(), BorderLayout.NORTH); t.add(toolSeparator = new JSeparator(JSeparator.HORIZONTAL), BorderLayout.SOUTH); toolSeparator.setVisible(panel.getToolBar().isVisible()); final SshToolsApplicationPanel pnl = panel; panel.getToolBar().addComponentListener(new ComponentAdapter() { public void componentHidden(ComponentEvent evt) { log.debug("Tool separator is now " + pnl.getToolBar().isVisible()); toolSeparator.setVisible(pnl.getToolBar().isVisible()); } }); p.add(t, BorderLayout.NORTH); } p.add(panel, BorderLayout.CENTER); if (panel.getStatusBar() != null) { p.add(panel.getStatusBar(), BorderLayout.SOUTH); } getContentPane().setLayout(new GridLayout(1, 1)); getContentPane().add(p); // Watch for the frame closing setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent evt) { if (application != null) { application.closeContainer(SshToolsApplicationFrame.this); } else { int confirm = JOptionPane.showOptionDialog(SshToolsApplicationFrame.this, "Close " + getTitle() + "?", "Close Operation", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, null, null); if (confirm == 0) { hide(); } } } }); // If this is the first frame, center the window on the screen Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); boolean found = false; if (application != null && application.getContainerCount() != 0) { for (int i = 0; (i < application.getContainerCount()) && !found; i++) { SshToolsApplicationContainer c = application.getContainerAt(i); if (c instanceof SshToolsApplicationFrame) { SshToolsApplicationFrame f = (SshToolsApplicationFrame) c; setSize(f.getSize()); Point newLocation = new Point(f.getX(), f.getY()); newLocation.x += 48; newLocation.y += 48; if (newLocation.x > (screenSize.getWidth() - 64)) { newLocation.x = 0; } if (newLocation.y > (screenSize.getHeight() - 64)) { newLocation.y = 0; } setLocation(newLocation); found = true; } } } if (!found) { // Is there a previous stored geometry we can use? if (PreferencesStore.preferenceExists(PREF_LAST_FRAME_GEOMETRY)) { setBounds(PreferencesStore.getRectangle(PREF_LAST_FRAME_GEOMETRY, getBounds())); } else { pack(); UIUtil.positionComponent(SwingConstants.CENTER, this); } } }