javax.swing.JDialog Java Examples

The following examples show how to use javax.swing.JDialog. 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: WrongBackgroundColor.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
public static void main(final String[] args)
        throws InvocationTargetException, InterruptedException {
    SwingUtilities.invokeAndWait(() -> {
        UIDefaults ui = UIManager.getDefaults();
        ui.put("control", new ColorUIResource(54, 54, 54));
        final JDialog dialog = new JDialog();
        final JFrame frame = new JFrame();
        frame.pack();
        dialog.pack();
        final Color dialogBackground = dialog.getBackground();
        final Color frameBackground = frame.getBackground();
        frame.dispose();
        dialog.dispose();
        if (!dialogBackground.equals(frameBackground)) {
            System.err.println("Expected:" + frameBackground);
            System.err.println("Actual:" + dialogBackground);
            throw new RuntimeException("Wrong background color");
        }
    });
}
 
Example #2
Source File: Messages.java    From jclic with GNU General Public License v2.0 6 votes vote down vote up
public static boolean showDlg(final JDialog dialog) {
  if (SwingUtilities.isEventDispatchThread()) {
    dialog.setVisible(true);
  } else {
    try {
      SwingUtilities.invokeAndWait(new Runnable() {
        public void run() {
          dialog.setVisible(true);
        }
      });
    } catch (Exception ex) {
      System.err.println("Show dialog error: " + ex);
      return false;
    }
  }
  return true;
}
 
Example #3
Source File: JavaAgentTest.java    From marathonv5 with Apache License 2.0 6 votes vote down vote up
public void switchTo() throws Throwable {
    SwingUtilities.invokeAndWait(new Runnable() {
        @Override
        public void run() {
            d2 = new JDialog(frame, false);
            d2.setName("dialog-2");
            d2.setTitle("My Dialog 2");
            JButton b = new JButton("Click-Me-2");
            b.setName("click-me-2");
            d2.getContentPane().add(b);
            d2.pack();
            d2.setVisible(true);
        }
    });
    Collection<String> windowHandles = driver.getWindowHandles();
    AssertJUnit.assertEquals(2, windowHandles.size());
    driver.switchTo().window("dialog-2");
    AssertJUnit.assertNotNull(driver.findElementByName("click-me-2"));
    SwingUtilities.invokeAndWait(new Runnable() {
        @Override
        public void run() {
            d2.dispose();
        }
    });
}
 
Example #4
Source File: HelpMenu.java    From triplea with GNU General Public License v3.0 6 votes vote down vote up
private static JDialog createInformationDialog(final JComponent component, final String title) {
  final JDialog dialog = new JDialog((JFrame) null, title);
  dialog.add(component, BorderLayout.CENTER);
  final JPanel buttons = new JPanel();
  final JButton button =
      new JButton(
          SwingAction.of(
              "OK",
              event -> {
                dialog.setVisible(false);
                dialog.removeAll();
                dialog.dispose();
              }));
  buttons.add(button);
  dialog.getRootPane().setDefaultButton(button);
  dialog.add(buttons, BorderLayout.SOUTH);
  dialog.pack();
  dialog.addWindowListener(
      new WindowAdapter() {
        @Override
        public void windowOpened(final WindowEvent e) {
          button.requestFocus();
        }
      });
  return dialog;
}
 
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: ChangePasswordPanel.java    From triplea with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Shows this panel in a modal dialog.
 *
 * @param parent The dialog parent window.
 * @return New password entered by user, otherwise null if the window is closed.
 */
private Optional<String> show(final Window parent) {
  dialog = new JDialog(JOptionPane.getFrameForComponent(parent), "", true);
  dialog.getContentPane().add(this);
  SwingKeyBinding.addKeyBinding(this, KeyCode.ESCAPE, this::close);
  dialog.pack();
  dialog.setLocationRelativeTo(parent);
  dialog.setVisible(true);
  dialog.dispose();
  dialog = null;
  if (!validatePasswordsAndUpdateValidationText()) {
    return Optional.empty();
  }

  final char[] password = passwordField.getPassword();
  if (rememberPassword.isSelected()) {
    ClientSetting.lobbySavedPassword.setValueAndFlush(password);
  } else {
    ClientSetting.lobbySavedPassword.resetValue();
  }
  return Optional.of(Sha512Hasher.hashPasswordWithSalt(String.valueOf(password)));
}
 
Example #7
Source File: ExtractDialog.java    From SubTitleSearcher with Apache License 2.0 6 votes vote down vote up
private void initComponents() {
	ExtractDialog _this = this;
	setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
	// setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
	setIconImage(MainWin.icon);
	setSize(820, 460);
	// setResizable(false);

	setLocationRelativeTo(this.getParent());
	setTitle("请选择压缩包中要保存的字幕文件");

	this.addWindowListener(new WindowAdapter() {
		public void windowClosing(WindowEvent e) {
			_this.clear();
			_this.dispose();
		}
	});

	add(bsPanel, BorderLayout.CENTER);
	openUrl(MainWin.class.getResource("/html/extract_dialog.html").toExternalForm());

}
 
Example #8
Source File: Test4177735.java    From openjdk-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 #9
Source File: MashapeExtractorUI.java    From wandora with GNU General Public License v3.0 6 votes vote down vote up
public void open(Wandora w, Context c) {
    context = c;
    wandora = w;
    accepted = false;
    dialog = new JDialog(w, true);
    dialog.setSize(550, 500);
    dialog.add(this);
    dialog.setTitle("Mashape API extractor");
    UIBox.centerWindow(dialog, w);
    if(apikey != null){
        forgetButton.setEnabled(true);
    } else {
        forgetButton.setEnabled(false);
    }
    dialog.setVisible(true);
}
 
Example #10
Source File: Metalworks.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) {
    UIManager.put("swing.boldMetal", Boolean.FALSE);
    JDialog.setDefaultLookAndFeelDecorated(true);
    JFrame.setDefaultLookAndFeelDecorated(true);
    Toolkit.getDefaultToolkit().setDynamicLayout(true);
    System.setProperty("sun.awt.noerasebackground", "true");
    try {
        UIManager.setLookAndFeel(new MetalLookAndFeel());
    } catch (UnsupportedLookAndFeelException e) {
        System.out.println(
                "Metal Look & Feel not supported on this platform. \n"
                + "Program Terminated");
        System.exit(0);
    }
    JFrame frame = new MetalworksFrame();
    frame.setVisible(true);
}
 
Example #11
Source File: NotifyExceptionTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void testYesDialogShown() throws Exception {
    Frame mainWindow = WindowManager.getDefault().getMainWindow();
    final JDialog modalDialog = new HiddenDialog( mainWindow, true );
    DD.toReturn = modalDialog;

    Logger l = Logger.getLogger(getName());
    l.setLevel(Level.ALL);
    System.setProperty("netbeans.exception.report.min.level", "200");
    l.log(Level.CONFIG, "Something is wrong", new NullPointerException("npe"));
    waitEQ();
    assertNotNull("Really returned", DD.lastDescriptor);
    assertEquals("It is DialogDescriptor", DialogDescriptor.class, DD.lastDescriptor.getClass());
    DialogDescriptor dd = (DialogDescriptor)DD.lastDescriptor;
    assertFalse( "The request is for non-modal dialog", dd.isModal());
    assertFalse("Main window is not visible", mainWindow.isVisible());
}
 
Example #12
Source File: BrowseButton.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
public BrowseButton(final JDialog parentDialog, final JTextField targetField) {
    super("Browse ...");
    addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent ae) {
            int returnVal = fileChooser.showOpenDialog(parentDialog);
            if (returnVal == JFileChooser.APPROVE_OPTION) {
                try {
                    targetField.setText(fileChooser.getSelectedFile().getCanonicalPath());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    });
}
 
Example #13
Source File: RedisRefreshService.java    From gameserver with Apache License 2.0 6 votes vote down vote up
public RedisRefreshService(RedisTreeTableModel treeTableModel, String host, int port) {
	this.treeTableModel = treeTableModel;
	this.host = host;
	this.port = port;
	
	panel = new JXPanel();
	panel.setLayout(new MigLayout("wrap 1"));
	panel.add(label, "growx, wrap 20");
	panel.add(progressBar, "grow, push");

	dialog = new JDialog();
	dialog.add(panel);
	dialog.setSize(300, 120);
	Point p = WindowUtils.getPointForCentering(dialog);
	dialog.setLocation(p);
	dialog.setModal(true);
	dialog.setResizable(false);
	dialog.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
}
 
Example #14
Source File: DiffApplyIgnoreTest.java    From ghidra with Apache License 2.0 6 votes vote down vote up
@Test
public void testCodeUnitIgnore() throws Exception {
	openDiff(diffTestP1, diffTestP2);
	JDialog dialog = waitForJDialog(tool.getToolFrame(), "Memory Differs", 2000);
	assertNotNull(dialog);
	pressButtonByText(dialog, "OK");
	waitForPostedSwingRunnables();
	showApplySettings();

	ProgramSelection origDiffs = diffPlugin.getDiffHighlightSelection();
	ignore(codeUnitApplyCB);
	AddressSet as = new AddressSet(addr("10024b8"), addr("10024b8"));
	setDiffSelection(as);
	apply();
	assertEquals(origDiffs, diffPlugin.getDiffHighlightSelection());
}
 
Example #15
Source File: DiffApplyIgnoreTest.java    From ghidra with Apache License 2.0 6 votes vote down vote up
@Test
public void testPropertyIgnore() throws Exception {
	openDiff(diffTestP1, diffTestP2);
	JDialog dialog = waitForJDialog(tool.getToolFrame(), "Memory Differs", 2000);
	assertNotNull(dialog);
	pressButtonByText(dialog, "OK");
	waitForPostedSwingRunnables();
	showApplySettings();

	ProgramSelection origDiffs = diffPlugin.getDiffHighlightSelection();
	ignore(propertiesApplyCB);
	AddressSet as = new AddressSet(addr("100248c"), addr("100248e"));
	setDiffSelection(as);
	apply();
	assertEquals(origDiffs, diffPlugin.getDiffHighlightSelection());
}
 
Example #16
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 #17
Source File: TestExportToTexTask.java    From Zettelkasten with GNU General Public License v3.0 6 votes vote down vote up
@Before
public void initialize() throws Exception {
	settings = TestObjectFactory.ZKN3Settings.ZKN3_TRICKY_MARKDOWN;
	daten = TestObjectFactory.getDaten(settings);

	JDialog parent = null;
	Application app = org.jdesktop.application.Application
			.getInstance(ZettelkastenApp.class);
	JLabel label = new JLabel();
	TasksData td = null;
	DesktopData dt = null;
	File fp = null;
	BibTex bto = null;
	ArrayList<Object> ee = null;
	int type = 0;
	int part = 0;
	DefaultMutableTreeNode n = null;
	boolean bibtex = false;
	boolean ihv = false;
	boolean numberprefix = false;
	boolean contenttable = false;

	exportToTexTask = new ExportToTexTask(app, parent, label, td, daten,
			dt, settings.settings, bto, fp, ee, type, part, n, bibtex, ihv,
			numberprefix, contenttable, false);
}
 
Example #18
Source File: Metalworks.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) {
    UIManager.put("swing.boldMetal", Boolean.FALSE);
    JDialog.setDefaultLookAndFeelDecorated(true);
    JFrame.setDefaultLookAndFeelDecorated(true);
    Toolkit.getDefaultToolkit().setDynamicLayout(true);
    System.setProperty("sun.awt.noerasebackground", "true");
    try {
        UIManager.setLookAndFeel(new MetalLookAndFeel());
    } catch (UnsupportedLookAndFeelException e) {
        System.out.println(
                "Metal Look & Feel not supported on this platform. \n"
                + "Program Terminated");
        System.exit(0);
    }
    JFrame frame = new MetalworksFrame();
    frame.setVisible(true);
}
 
Example #19
Source File: ListObjDef.java    From openprodoc with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * 
 * @return
 * @throws PDException
 */
@Override
protected JDialog EditMode() throws PDException
{
MantObjDefs MU = new MantObjDefs(Fparent, true);
MU.setRecord(getPDTableModel().getElement(getSelectedRow()));
MU.EditMode();
return(MU);
}
 
Example #20
Source File: ListTaskCron.java    From openprodoc with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * 
 * @return
 * @throws PDException
 */
@Override
protected JDialog CopyMode() throws PDException
{
MantTaskCron MU = new MantTaskCron(Fparent, true);
MU.setRecord(getPDTableModel().getElement(getSelectedRow()));
MU.CopyMode();
return(MU);
}
 
Example #21
Source File: WindowClosedEventOnDispose.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Test if a dialog fire the WINDOW_CLOSED event
 * on parent dispose().
 * @throws Exception
 */
public static void testVisibleChildParentDispose() throws Exception {
    JFrame f = new JFrame();
    JDialog dlg = new JDialog(f);
    Listener l = new Listener();
    dlg.addWindowListener(l);
    dlg.setVisible(true);
    f.dispose();
    waitEvents();

    assertEquals(1, l.getCount());
}
 
Example #22
Source File: MiniMap.java    From megamek with GNU General Public License v2.0 5 votes vote down vote up
public void mouseReleased(MouseEvent me) {
    // Center main map on clicked area, if there was no dragging
    if (m_dialog instanceof JDialog && !dragging) {
        processMouseClick(me.getX(), me.getY(), me);
    }
    // Clear up variables related to dragging
    dragging = false;
    setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
}
 
Example #23
Source File: NbErrorManagerTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public Dialog createDialog(DialogDescriptor descriptor) {
    lastDescriptor = descriptor;
    return new JDialog() {
        @SuppressWarnings("deprecation")
        @Override
        public void show() {}
    };
}
 
Example #24
Source File: View.java    From jpexs-decompiler with GNU General Public License v3.0 5 votes vote down vote up
public static void installEscapeCloseOperation(final JDialog dialog) {
    Action dispatchClosing = new AbstractAction() {
        @Override
        public void actionPerformed(ActionEvent event) {
            dialog.dispatchEvent(new WindowEvent(
                    dialog, WindowEvent.WINDOW_CLOSING));
        }
    };
    JRootPane root = dialog.getRootPane();
    root.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(
            escapeStroke, dispatchWindowClosingActionMapKey);
    root.getActionMap().put(dispatchWindowClosingActionMapKey, dispatchClosing);
}
 
Example #25
Source File: DocumentsDlg.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public static void showDocumentsDialog() {
    DocumentsDlg documentsPanel = getDefault();
    DialogDescriptor dlgDesc = new DialogDescriptor(
        documentsPanel,
        NbBundle.getMessage(DocumentsDlg.class, "CTL_DocumentsTitle"),
        true, // is modal!!
        new Object[0],
        // make "switcch to document" button default
        getDefault().jButtonActivate,
        DialogDescriptor.DEFAULT_ALIGN,
        null,
        null
    );
    dlgDesc.setHelpCtx( null ); //hide the default Help button
    final Dialog dlg = DialogDisplayer.getDefault().createDialog(dlgDesc);
    dlg.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(DocumentsDlg.class, "ACSD_DocumentsDialog"));
    if( dlg instanceof JDialog ) {
        HelpCtx.setHelpIDString(((JDialog)dlg).getRootPane(), documentsPanel.getHelpCtx().getHelpID());
    }
    getDefault().updateNodes();
    
    if (getDefault().previousDialogSize != null) {
        dlg.setSize(getDefault().previousDialogSize);
        dlg.setLocationRelativeTo(null);
    }

    dlg.setVisible(true);
    getDefault().clearNodes();
}
 
Example #26
Source File: NbErrorManagerUserQuestionTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public Dialog createDialog(DialogDescriptor descriptor) {
    lastDescriptor = descriptor;
    return new JDialog() {
        @SuppressWarnings("deprecation")
        @Override
        public void show() {
        }
    };
}
 
Example #27
Source File: CodeTemplatesOperator.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public static CodeTemplatesOperator invoke(boolean openOptions) {
    if (openOptions) {
        optionsOperator = OptionsOperator.invoke();
    } else {
        optionsOperator = new OptionsOperator();
    }
    CodeTemplatesOperator codeTemplatesOperator = new CodeTemplatesOperator((JDialog) optionsOperator.getSource());
    codeTemplatesOperator.switchToTemplates();
    if(defaultTemplates==null) { // first invocation -> save default values for java
        codeTemplatesOperator.switchLanguage("Java");
        defaultTemplates = codeTemplatesOperator.dumpTemplatesTable();
    }
    return codeTemplatesOperator;
}
 
Example #28
Source File: HistogramDialog.java    From mzmine2 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 
 * @param title
 * @param data
 * @param binWidth zero (0) for auto detection, -1 to keep last binWidth
 */
public HistogramDialog(String title, String xLabel, HistogramData data, double binWidth) {
  this.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
  setTitle(title);
  setBounds(100, 100, 1000, 800);
  getContentPane().setLayout(new BorderLayout());
  histo = new HistogramPanel(xLabel, data, binWidth);
  getContentPane().add(histo, BorderLayout.CENTER);
  this.setTitle(title);
}
 
Example #29
Source File: InputMethodPopupMenu.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
static InputMethodPopupMenu getInstance(Component client, String title) {
    if ((client instanceof JFrame) ||
        (client instanceof JDialog)) {
            return new JInputMethodPopupMenu(title);
    } else {
        return new AWTInputMethodPopupMenu(title);
    }
}
 
Example #30
Source File: ProgressPanel.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void open(JComponent progressComponent) {
    holder.add(progressComponent, BorderLayout.CENTER);

    DialogDescriptor dd = new DialogDescriptor(
            this,
            NbBundle.getMessage(ProgressPanel.class, "MSG_PleaseWait"),
            true,
            new Object[0],
            DialogDescriptor.NO_OPTION,
            DialogDescriptor.DEFAULT_ALIGN,
            null,
            null,
            true);
    dialog = DialogDisplayer.getDefault().createDialog(dd);
    if (dialog instanceof JDialog) {
        JDialog jDialog = ((JDialog) dialog);
        jDialog.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
        JRootPane rootPane = jDialog.getRootPane();
        rootPane.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), "cancel"); // NOI18N
        rootPane.getActionMap().put("cancel", new AbstractAction() { // NOI18N
            @Override
            public void actionPerformed(ActionEvent event) {
                if (cancelButton.isEnabled()) {
                    cancelButton.doClick();
                }
            }
        });
    }
    dialog.setResizable(false);
    dialog.setVisible(true);
}