Java Code Examples for javax.swing.JDialog#dispose()

The following examples show how to use javax.swing.JDialog#dispose() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GameInfoDialog.java    From FancyBing with GNU General Public License v3.0 6 votes vote down vote up
public static void show(Component parent, GameInfo info,
                        MessageDialogs messageDialogs)
{
    GameInfoDialog gameInfo = new GameInfoDialog(info);
    JDialog dialog = gameInfo.createDialog(parent, i18n("TIT_GAMEINFO"));
    boolean done = false;
    while (! done)
    {
        dialog.setVisible(true);
        Object value = gameInfo.getValue();
        if (! (value instanceof Integer)
            || ((Integer)value).intValue() != JOptionPane.OK_OPTION)
            return;
        done = gameInfo.validate(parent, messageDialogs);
    }
    dialog.dispose();
    gameInfo.updateGameInfo(info);
}
 
Example 2
Source File: Test4177735.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    JColorChooser chooser = new JColorChooser();
    AbstractColorChooserPanel[] panels = chooser.getChooserPanels();
    chooser.setChooserPanels(new AbstractColorChooserPanel[] { panels[1] });

    JDialog dialog = show(chooser);
    pause(DELAY);

    dialog.dispose();
    pause(DELAY);

    Test4177735 test = new Test4177735();
    SwingUtilities.invokeAndWait(test);
    if (test.count != 0) {
        throw new Error("JColorChooser leaves " + test.count + " threads running");
    }
}
 
Example 3
Source File: Test4177735.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    JColorChooser chooser = new JColorChooser();
    AbstractColorChooserPanel[] panels = chooser.getChooserPanels();
    chooser.setChooserPanels(new AbstractColorChooserPanel[] { panels[1] });

    JDialog dialog = show(chooser);
    pause(DELAY);

    dialog.dispose();
    pause(DELAY);

    Test4177735 test = new Test4177735();
    SwingUtilities.invokeAndWait(test);
    if (test.count != 0) {
        throw new Error("JColorChooser leaves " + test.count + " threads running");
    }
}
 
Example 4
Source File: Test4177735.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    JColorChooser chooser = new JColorChooser();
    AbstractColorChooserPanel[] panels = chooser.getChooserPanels();
    chooser.setChooserPanels(new AbstractColorChooserPanel[] { panels[1] });

    JDialog dialog = show(chooser);
    pause(DELAY);

    dialog.dispose();
    pause(DELAY);

    Test4177735 test = new Test4177735();
    SwingUtilities.invokeAndWait(test);
    if (test.count != 0) {
        throw new Error("JColorChooser leaves " + test.count + " threads running");
    }
}
 
Example 5
Source File: Test4177735.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    JColorChooser chooser = new JColorChooser();
    AbstractColorChooserPanel[] panels = chooser.getChooserPanels();
    chooser.setChooserPanels(new AbstractColorChooserPanel[] { panels[1] });

    JDialog dialog = show(chooser);
    pause(DELAY);

    dialog.dispose();
    pause(DELAY);

    Test4177735 test = new Test4177735();
    SwingUtilities.invokeAndWait(test);
    if (test.count != 0) {
        throw new Error("JColorChooser leaves " + test.count + " threads running");
    }
}
 
Example 6
Source File: ErrorDialog.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Create a new Dialog with a title and a message.
 * @param message
 * @param title 
 */
public ErrorDialog(String message, String title) {
    setTitle(title);
    setSize(new Dimension(600, 400));
    setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
    setLocationRelativeTo(null);   
    
    Container container = getContentPane();
    container.setLayout(new BorderLayout());
    
    JTextArea textArea = new JTextArea();
    textArea.setText(message);
    textArea.setEditable(false);
    textArea.setMargin(new Insets(PADDING, PADDING, PADDING, PADDING));
    add(new JScrollPane(textArea), BorderLayout.CENTER);
    
    final JDialog dialog = this;
    JButton button = new JButton(new AbstractAction("OK"){
        @Override
        public void actionPerformed(ActionEvent e) {
            dialog.dispose();
        }
    });
    add(button, BorderLayout.SOUTH);
}
 
Example 7
Source File: Test4177735.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    JColorChooser chooser = new JColorChooser();
    AbstractColorChooserPanel[] panels = chooser.getChooserPanels();
    chooser.setChooserPanels(new AbstractColorChooserPanel[] { panels[1] });

    JDialog dialog = show(chooser);
    pause(DELAY);

    dialog.dispose();
    pause(DELAY);

    Test4177735 test = new Test4177735();
    SwingUtilities.invokeAndWait(test);
    if (test.count != 0) {
        throw new Error("JColorChooser leaves " + test.count + " threads running");
    }
}
 
Example 8
Source File: Test4177735.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    JColorChooser chooser = new JColorChooser();
    AbstractColorChooserPanel[] panels = chooser.getChooserPanels();
    chooser.setChooserPanels(new AbstractColorChooserPanel[] { panels[1] });

    JDialog dialog = show(chooser);
    pause(DELAY);

    dialog.dispose();
    pause(DELAY);

    Test4177735 test = new Test4177735();
    SwingUtilities.invokeAndWait(test);
    if (test.count != 0) {
        throw new Error("JColorChooser leaves " + test.count + " threads running");
    }
}
 
Example 9
Source File: JFontChooser.java    From PacketProxy with Apache License 2.0 6 votes vote down vote up
public int showDialog(Component parent)
{
    dialogResultValue = ERROR_OPTION;
    JDialog dialog = createDialog(parent);
    dialog.addWindowListener(new WindowAdapter()
    {
        public void windowClosing(WindowEvent e)
        {
            dialogResultValue = CANCEL_OPTION;
        }
    });

    dialog.setVisible(true);
    dialog.dispose();
    dialog = null;

    return dialogResultValue;
}
 
Example 10
Source File: Test4234761.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
    JColorChooser chooser = new JColorChooser(COLOR);
    JDialog dialog = Test4177735.show(chooser);

    PropertyChangeListener listener = new Test4234761();
    chooser.addPropertyChangeListener("color", listener); // NON-NLS: property name

    JTabbedPane tabbedPane = (JTabbedPane) chooser.getComponent(0);
    tabbedPane.setSelectedIndex(1); // HSB tab index

    if (!chooser.getColor().equals(COLOR)) {
        listener.propertyChange(null);
    }
    dialog.dispose();
}
 
Example 11
Source File: Test4234761.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
    JColorChooser chooser = new JColorChooser(COLOR);
    JDialog dialog = Test4177735.show(chooser);

    PropertyChangeListener listener = new Test4234761();
    chooser.addPropertyChangeListener("color", listener); // NON-NLS: property name

    JTabbedPane tabbedPane = (JTabbedPane) chooser.getComponent(0);
    tabbedPane.setSelectedIndex(1); // HSB tab index

    if (!chooser.getColor().equals(COLOR)) {
        listener.propertyChange(null);
    }
    dialog.dispose();
}
 
Example 12
Source File: Test4234761.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
    JColorChooser chooser = new JColorChooser(COLOR);
    JDialog dialog = Test4177735.show(chooser);

    PropertyChangeListener listener = new Test4234761();
    chooser.addPropertyChangeListener("color", listener); // NON-NLS: property name

    JTabbedPane tabbedPane = (JTabbedPane) chooser.getComponent(0);
    tabbedPane.setSelectedIndex(1); // HSB tab index

    if (!chooser.getColor().equals(COLOR)) {
        listener.propertyChange(null);
    }
    dialog.dispose();
}
 
Example 13
Source File: TimeLeftDialog.java    From FancyBing with GNU General Public License v3.0 5 votes vote down vote up
public static void show(Component parent, Game game, ConstNode node,
                        MessageDialogs messageDialogs)
{
    ConstGameInfo info = game.getGameInfoNode(node).getGameInfoConst();
    Clock clock = null;
    TimeSettings timeSettings = info.getTimeSettings();
    if (timeSettings != null)
    {
        clock = new Clock();
        clock.setTimeSettings(timeSettings);
        NodeUtil.restoreClock(node, clock);
    }
    TimeLeftDialog timeLeftDialog = new TimeLeftDialog(clock);
    JDialog dialog = timeLeftDialog.createDialog(parent,
                                                 i18n("TIT_TIME_LEFT"));
    boolean done = false;
    while (! done)
    {
        dialog.setVisible(true);
        Object value = timeLeftDialog.getValue();
        if (! (value instanceof Integer)
            || ((Integer)value).intValue() != JOptionPane.OK_OPTION)
            return;
        done = timeLeftDialog.validate(parent, messageDialogs);
    }
    for (GoColor c : BLACK_WHITE)
    {
        long timeLeft = timeLeftDialog.getTimeLeft(c);
        game.setTimeLeft(node, c, timeLeft / 1000L);
        int movesLeft = timeLeftDialog.getMovesLeft(c);
        if (movesLeft >= 0)
            game.setMovesLeft(node, c, movesLeft);
        game.restoreClock();
    }
    dialog.dispose();
}
 
Example 14
Source File: Test4234761.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
    JColorChooser chooser = new JColorChooser(COLOR);
    JDialog dialog = Test4177735.show(chooser);

    PropertyChangeListener listener = new Test4234761();
    chooser.addPropertyChangeListener("color", listener); // NON-NLS: property name

    JTabbedPane tabbedPane = (JTabbedPane) chooser.getComponent(0);
    tabbedPane.setSelectedIndex(1); // HSB tab index

    if (!chooser.getColor().equals(COLOR)) {
        listener.propertyChange(null);
    }
    dialog.dispose();
}
 
Example 15
Source File: ForgotPasswordPanel.java    From triplea with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Shows this panel in a modal dialog.
 *
 * @param parent The dialog parent window.
 * @return {@link ReturnValue#OK} if the user clicks 'okay' button, otherwise {@link
 *     ReturnValue#CANCEL}.
 */
ReturnValue show(final Window parent) {
  dialog = new JDialog(JOptionPane.getFrameForComponent(parent), title, true);
  dialog.getContentPane().add(this);
  SwingKeyBinding.addKeyBinding(dialog, KeyCode.ESCAPE, this::close);
  dialog.pack();
  dialog.setLocationRelativeTo(parent);
  dialog.setVisible(true);
  dialog.dispose();
  dialog = null;
  return returnValue;
}
 
Example 16
Source File: AbegoTreeLayoutForNetbeansDemo.java    From treelayout with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private static void showScene(TreeScene scene, String title) {
	JScrollPane panel = new JScrollPane(scene.createView());
	JDialog dialog = new JDialog();
	dialog.setModal(true);
	dialog.setTitle(title);
	dialog.add(panel, BorderLayout.CENTER);
	dialog.setSize(800, 600);
	dialog.setVisible(true);
	dialog.dispose();
}
 
Example 17
Source File: UsernamePassword.java    From OpenDA with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Ask using a GUI for the username and password.
 */
private void readFromGUI() {
   // Create fields for user name.
   final JTextField usernameField = new JTextField(20);
   usernameField.setText(this.username);
   final JLabel usernameLabel = new JLabel("Username: ");
   usernameLabel.setLabelFor(usernameField);
   final JPanel usernamePane = new JPanel(new FlowLayout(FlowLayout.TRAILING));
   usernamePane.add(usernameLabel);
   usernamePane.add(usernameField);

   // Create fields for password.
   final JPasswordField passwordField = new JPasswordField(20);
   passwordField.setText(this.password);
   final JLabel passwordLabel = new JLabel("Password: ");
   passwordLabel.setLabelFor(passwordField);
   final JPanel passwordPane = new JPanel(new FlowLayout(FlowLayout.TRAILING));
   passwordPane.add(passwordLabel);
   passwordPane.add(passwordField);

   // Create panel
   final JPanel main = new JPanel();
   main.setLayout(new BoxLayout(main, BoxLayout.PAGE_AXIS));
   main.add(usernamePane);
   main.add(passwordPane);

   // Create and handle dialog
   final JOptionPane jop = new JOptionPane(main, JOptionPane.QUESTION_MESSAGE, JOptionPane.OK_CANCEL_OPTION);
   final JDialog dialog = jop.createDialog("User name and password");
   dialog.addComponentListener(new ComponentAdapter() {
      
      public void componentShown(ComponentEvent e) {
         SwingUtilities.invokeLater(new Runnable() {
            
            public void run() {
               if (usernameField.getText().isEmpty())
               {
                  usernameField.requestFocusInWindow();
               }
               else
               {
                  passwordField.requestFocusInWindow();
               }
            }
         });
      }
   });
   dialog.setVisible(true);
   final Integer result = (Integer) jop.getValue();
   dialog.dispose();
   if (result.intValue() == JOptionPane.OK_OPTION) {
      this.username = usernameField.getText();

      final char[] pwd = passwordField.getPassword();
      this.password = new String(pwd);
   }
}
 
Example 18
Source File: BookmarkEditor.java    From FancyBing with GNU General Public License v3.0 4 votes vote down vote up
public Bookmark editItem(Component parent, String title,
                         Bookmark bookmark, boolean selectName,
                         MessageDialogs messageDialogs)
{
    JPanel panel = new JPanel(new BorderLayout(GuiUtil.SMALL_PAD, 0));
    m_panelLeft = new JPanel(new GridLayout(0, 1, 0, GuiUtil.PAD));
    panel.add(m_panelLeft, BorderLayout.WEST);
    m_panelRight =
        new JPanel(new GridLayout(0, 1, 0, GuiUtil.PAD));
    panel.add(m_panelRight, BorderLayout.CENTER);
    m_name = createEntry("LB_BOOKMARKEDITOR_NAME", 25, bookmark.m_name);
    String file = "";
    if (bookmark.m_file != null)
        file = bookmark.m_file.toString();
    m_file = createEntry("LB_BOOKMARKEDITOR_FILE", 25, file);
    String move = "";
    if (bookmark.m_move > 0)
        move = Integer.toString(bookmark.m_move);
    m_move = createEntry("LB_BOOKMARKEDITOR_MOVE", 10, move);
    m_variation = createEntry("LB_BOOKMARKEDITOR_VARIATION", 10,
                              bookmark.m_variation);
    JOptionPane optionPane = new JOptionPane(panel,
                                             JOptionPane.PLAIN_MESSAGE,
                                             JOptionPane.OK_CANCEL_OPTION);
    JDialog dialog = optionPane.createDialog(parent, title);
    boolean done = false;
    while (! done)
    {
        if (selectName)
            m_name.selectAll();
        dialog.addWindowListener(new WindowAdapter() {
                public void windowActivated(WindowEvent e) {
                    m_name.requestFocusInWindow();
                }
            });
        dialog.setVisible(true);
        Object value = optionPane.getValue();
        if (! (value instanceof Integer)
            || ((Integer)value).intValue() != JOptionPane.OK_OPTION)
            return null;
        done = validate(parent, messageDialogs);
    }
    String newName = m_name.getText().trim();
    File newFile = new File(m_file.getText());
    int newMove = getMove();
    String newVariation = m_variation.getText().trim();
    Bookmark newBookmark =
        new Bookmark(newName, newFile, newMove, newVariation);
    dialog.dispose();
    return newBookmark;
}
 
Example 19
Source File: ActionDurationDialog.java    From triplea with GNU General Public License v3.0 4 votes vote down vote up
private void close(final JDialog dialog) {
  dialog.setVisible(false);
  dialog.dispose();
}
 
Example 20
Source File: AltConfigWizard.java    From CogniCrypt with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * This method is called once the user selects an instance. It writes the instance to an xml file and calls the code generation.
 *
 * @return <code>true</code>/<code>false</code> if writing instance file and code generation are (un)successful
 */
@Override
public boolean performFinish() {
	boolean ret = false;
	final CodeGenerators genKind = selectedTask.getCodeGen();
	CodeGenerator codeGenerator = null;
	String additionalResources = selectedTask.getAdditionalResources();
	final LocatorPage currentPage = (LocatorPage) getContainer().getCurrentPage();
	IResource targetFile = (IResource) currentPage.getSelectedResource().getFirstElement();

	String taskName = selectedTask.getName();
	JOptionPane optionPane = new JOptionPane("CogniCrypt is now generating code that implements " + selectedTask.getDescription() + "\ninto file " + ((targetFile != null)
		? targetFile.getName()
		: "Output.java") + ". This should take no longer than a few seconds.", JOptionPane.INFORMATION_MESSAGE, JOptionPane.DEFAULT_OPTION, null, new Object[] {}, null);
	JDialog waitingDialog = optionPane.createDialog("Generating Code");
	waitingDialog.setModal(false);
	waitingDialog.setVisible(true);
	Configuration chosenConfig = null;
	try {
		switch (genKind) {
			case CrySL:
				CrySLBasedCodeGenerator.clearParameterCache();
				File templateFile = CodeGenUtils.getResourceFromWithin(selectedTask.getCodeTemplate()).listFiles()[0];
				codeGenerator = new CrySLBasedCodeGenerator(targetFile);
				String projectRelDir = Constants.outerFileSeparator + codeGenerator.getDeveloperProject()
					.getSourcePath() + Constants.outerFileSeparator + Constants.PackageName + Constants.outerFileSeparator;
				String pathToTemplateFile = projectRelDir + templateFile.getName();
				String resFileOSPath = "";

				IPath projectPath = targetFile.getProject().getRawLocation();
				if (projectPath == null) {
					projectPath = targetFile.getProject().getLocation();
				}
				resFileOSPath = projectPath.toOSString() + pathToTemplateFile;

				Files.createDirectories(Paths.get(projectPath.toOSString() + projectRelDir));
				Files.copy(templateFile.toPath(), Paths.get(resFileOSPath), StandardCopyOption.REPLACE_EXISTING);
				codeGenerator.getDeveloperProject().refresh();

				resetAnswers();
				chosenConfig = new CrySLConfiguration(resFileOSPath, ((CrySLBasedCodeGenerator) codeGenerator).setUpTemplateClass(pathToTemplateFile));
				break;
			case XSL:
				this.constraints = (this.constraints != null) ? this.constraints : new HashMap<>();
				final InstanceGenerator instanceGenerator = new InstanceGenerator(CodeGenUtils.getResourceFromWithin(selectedTask.getModelFile())
					.getAbsolutePath(), "c0_" + taskName, selectedTask.getDescription());
				instanceGenerator.generateInstances(this.constraints);

				// Initialize Code Generation
				codeGenerator = new XSLBasedGenerator(targetFile, selectedTask.getCodeTemplate());
				chosenConfig = new XSLConfiguration(instanceGenerator.getInstances().values().iterator()
					.next(), this.constraints, codeGenerator.getDeveloperProject().getProjectPath() + Constants.innerFileSeparator + Constants.pathToClaferInstanceFile);
				break;
			default:
				return false;
		}
		ret = codeGenerator.generateCodeTemplates(chosenConfig, additionalResources);

		try {
			codeGenerator.getDeveloperProject().refresh();
		} catch (CoreException e1) {
			Activator.getDefault().logError(e1);
		}

	} catch (Exception ex) {
		Activator.getDefault().logError(ex);
	} finally {

		waitingDialog.setVisible(false);
		waitingDialog.dispose();
	}

	return ret;
}