Java Utililty Methods JDialog

List of utility methods to do JDialog

Description

The list of methods to do JDialog are organized into topic(s).

Method

voidresizeDialogToScreen(JDialog dialog)
Update the size of the dialog to ensure it will fit on the screen.
Rectangle screenBounds = GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds();
final Dimension dialogSize = dialog.getSize();
if (dialogSize.height > screenBounds.height) {
    dialogSize.height = screenBounds.height;
if (dialogSize.width > screenBounds.width) {
    dialogSize.width = screenBounds.width;
dialog.setSize(dialogSize);
booleanrptaConfirmDialog(JDialog pJDialog, String pMensaje)
rpta Confirm Dialog
int rptaDialogo = JOptionPane.showConfirmDialog(pJDialog, pMensaje, "Mensaje del Sistema",
        JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
if (rptaDialogo == JOptionPane.YES_OPTION)
    return true;
else
    return false;
voidrunProgressBar(final Runnable runnable, final JDialog dialog)
Run progress bar.
Thread worker = new Thread() {
    @Override
    public void run() {
        try {
            runnable.run();
        } catch (Throwable e) {
            e.printStackTrace();
        } finally {
...
voidsetActionsMenu(JDialog dialog, MenuElement menu)
set Actions Menu
MenuElement[] subItems = menu.getSubElements();
for (int i = 0; i < subItems.length; i++) {
    MenuElement c = subItems[i];
    if (c instanceof JMenuItem) {
        final JMenuItem menuItem = (JMenuItem) c;
        if (menuItem.getAccelerator() != null) {
            String key = "hackAction" + counter++;
            dialog.getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW)
...
voidsetCursorFree(JDialog dialog)
Set cursor to free and enable application input.
setCursorFree(dialog.getRootPane().getGlassPane());
voidsetDirty(JDialog dialog, boolean isDirty)
set Dirty
setDirty(dialog.getRootPane(), isDirty);
voidsetHelpDialogLoc(JButton odsHelpButton, JDialog helpDialog)
set Help Dialog Loc
Point buttonPoint = odsHelpButton.getLocationOnScreen();
int dialogWidth = helpDialog.getSize().width;
int dialogHeight = helpDialog.getSize().height;
int helpDialogX = buttonPoint.x - dialogWidth / 2;
if (helpDialogX < 0) {
    helpDialogX = 0;
int helpDialogY = buttonPoint.y - dialogHeight - 10;
...
voidsetSize(JDialog dialog, int width, int height)
set the size of a dialog, but never sizes it smaller than the preferred size
dialog.pack();
Dimension size = dialog.getMinimumSize();
if (width > size.width) {
    size.width = width;
if (height > size.height) {
    size.height = height;
dialog.setSize(size);
voidsetWinVisible(final JDialog win, final boolean vis)
set Win Visible
SwingUtilities.invokeLater(new Runnable() {
    public void run() {
        win.setVisible(vis);
});
voidsizeDialog(JDialog dialog, int prefWidth, int prefHeight)
Utility method to size a Dialog box correctly.
sizeDialog(dialog, prefWidth, prefHeight, false);