Example usage for javax.swing JDialog add

List of usage examples for javax.swing JDialog add

Introduction

In this page you can find the example usage for javax.swing JDialog add.

Prototype

public Component add(String name, Component comp) 

Source Link

Document

Adds the specified component to this container.

Usage

From source file:Main.java

public static void main(String[] args) {
    JFrame parentFrame = new JFrame();
    parentFrame.setSize(500, 150);/* w w w.  j  a  v  a 2 s  . c  o  m*/
    JLabel jl = new JLabel();
    jl.setText("Count : 0");

    parentFrame.add(BorderLayout.CENTER, jl);
    parentFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    parentFrame.setVisible(true);

    final JDialog dlg = new JDialog(parentFrame, "Progress Dialog", true);
    JProgressBar dpb = new JProgressBar(0, 500);
    dlg.add(BorderLayout.CENTER, dpb);
    dlg.add(BorderLayout.NORTH, new JLabel("Progress..."));
    dlg.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
    dlg.setSize(300, 75);
    dlg.setLocationRelativeTo(parentFrame);

    Thread t = new Thread(new Runnable() {
        public void run() {
            dlg.setVisible(true);
        }
    });
    t.start();
    for (int i = 0; i <= 500; i++) {
        jl.setText("Count : " + i);
        dpb.setValue(i);
        if (dpb.getValue() == 500) {
            dlg.setVisible(false);
            System.exit(0);

        }
        try {
            Thread.sleep(25);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
    dlg.setVisible(true);
}

From source file:org.pgptool.gui.ui.importkey.KeyImporterView.java

@Override
protected JDialog initDialog(Window owner, Object constraints) {
    JDialog ret = new JDialog(owner, ModalityType.APPLICATION_MODAL);
    ret.setLayout(new BorderLayout());
    ret.setResizable(true);/*from  w w  w.  j av  a 2  s .  c  om*/
    ret.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
    ret.setTitle(Messages.get("action.importKey"));
    ret.add(pnl, BorderLayout.CENTER);
    ret.setMinimumSize(new Dimension(spacing(60), spacing(30)));

    initWindowGeometryPersister(ret, "keyImprt");

    return ret;
}

From source file:com.aw.swing.mvp.JDialogView.java

private void initializeDlg() {
    if (pst.isEmbeddedView()) {
        return;/*from  ww  w  .jav a 2  s.  c o m*/
    }
    JDialog dlg = (JDialog) parentContainer;

    dlg.add(viewLayout.mainPanel, BorderLayout.CENTER);

    //        SwingUtils.locateOnScreenCenter(dlg);
    SwingUtils.locateRelativeToMenu(dlg);
    dlg.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
    dlg.addWindowListener(new java.awt.event.WindowAdapter() {
        // todo ver cmo se va a hacer esto en la versin Filthy
        public void windowOpened(WindowEvent e) {
            if (pst != null) {
                pst.onWindowsOpened(e);
                pst.onWindowsOpenedInternalOnlyForAWFW(e);
                if (!pst.isReadOnly()) {
                    //                        pst.setFocusToCmpOnWindowOpen();
                    //                        ActionManager.instance().getVisualMgrForActions().repaintMainDisabledActions(pst.getActionRsr());
                } else {
                    pst.configureAsReanOnly();
                    JButton btnCancel = (JButton) pst.getIpView().getComponent("btnCancel");
                    if (btnCancel != null) {
                        btnCancel.requestFocusInWindow();
                    }
                }
            }
        }

        public void windowClosing(WindowEvent e) {
            MsgDisplayer.showMessage("sw.common.closeWindowDisabled");
        }

        public void windowActivated(WindowEvent e) {
            Object oppositeWindow = e.getOppositeWindow();

            if (oppositeWindow instanceof DlgMensaje) {
                logger.debug("Ignoring Windows activated for DlgMensaje");
                return;
            }
            if (oppositeWindow instanceof JDialog) {
                JDialog dlg = (JDialog) oppositeWindow;
                if (MessageDisplayer.GENERIC_MESSAGE_TITLE.equals(dlg.getTitle())) {
                    logger.debug("Ignoring Windows activated for System Msg");
                    return;
                }
            }
            logger.debug("Windows Activated:" + pst);
            AWWindowsManager.instance().setPresenterActivated(pst);
        }
    });
}

From source file:org.pgptool.gui.ui.keyslist.KeysListView.java

@Override
protected JDialog initDialog(Window owner, Object constraints) {
    JDialog ret = new JDialog(owner, ModalityType.APPLICATION_MODAL);
    ret.setMinimumSize(new Dimension(spacing(50), spacing(25)));
    ret.setLayout(new BorderLayout());
    ret.setResizable(true);//from   w  w w .  ja  v a  2s  . c o  m
    ret.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
    ret.setTitle(Messages.get("term.keysList"));
    ret.add(panelRoot, BorderLayout.CENTER);
    ret.setJMenuBar(menuBar);
    initWindowGeometryPersister(ret, "keysList");
    return ret;
}

From source file:net.sf.taverna.t2.workbench.ui.servicepanel.actions.AddServiceProviderAction.java

@Override
public void actionPerformed(ActionEvent e) {
    if (confProvider instanceof CustomizedConfigurePanelProvider) {
        final CustomizedConfigurePanelProvider provider = (CustomizedConfigurePanelProvider) confProvider;
        provider.createCustomizedConfigurePanel(new CustomizedConfigureCallBack() {
            @Override/*from  ww  w  .j a  va 2s . com*/
            public Configuration getTemplateConfig() {
                return (Configuration) provider.getConfiguration().clone();
            }

            @Override
            public ServiceDescriptionRegistry getServiceDescriptionRegistry() {
                return AddServiceProviderAction.this.getServiceDescriptionRegistry();
            }

            @Override
            public void newProviderConfiguration(Configuration providerConfig) {
                addNewProvider(providerConfig);
            }
        });
        return;
    }

    Configuration configuration;
    try {
        configuration = (Configuration) confProvider.getConfiguration().clone();
    } catch (Exception ex) {
        throw new RuntimeException("Can't clone configuration bean", ex);
    }
    JPanel buildEditor = buildEditor(configuration);
    String title = "Add " + confProvider.getName();
    JDialog dialog = new HelpEnabledDialog(getMainWindow(), title, true, null);
    JPanel iconPanel = new JPanel();
    iconPanel.add(new JLabel(confProvider.getIcon()), NORTH);
    dialog.add(iconPanel, WEST);
    dialog.add(buildEditor, CENTER);
    JPanel buttonPanel = new JPanel(new BorderLayout());
    final AddProviderAction addProviderAction = new AddProviderAction(configuration, dialog);
    JButton addProviderButton = new JButton(addProviderAction);
    buttonPanel.add(addProviderButton, WEST);

    dialog.add(buttonPanel, SOUTH);
    // When user presses "Return" key fire the action on the "Add" button
    addProviderButton.addKeyListener(new KeyAdapter() {
        @Override
        public void keyPressed(KeyEvent evt) {
            if (evt.getKeyCode() == VK_ENTER)
                addProviderAction.actionPerformed(null);
        }
    });
    dialog.getRootPane().setDefaultButton(addProviderButton);

    // dialog.setSize(buttonPanel.getPreferredSize());
    dialog.pack();
    dialog.setLocationRelativeTo(owner);
    //      dialog.setLocation(owner.getLocationOnScreen().x + owner.getWidth(),
    //            owner.getLocationOnScreen().y + owner.getHeight());
    dialog.setVisible(true);
}

From source file:net.sf.jabref.openoffice.AutoDetectPaths.java

public JDialog showProgressDialog(JDialog progressParent, String title, String message,
        boolean includeCancelButton) {
    fileSearchCancelled = false;//  w  w w  .j a v  a  2 s .  c  o  m
    JProgressBar bar = new JProgressBar(SwingConstants.HORIZONTAL);
    JButton cancel = new JButton(Localization.lang("Cancel"));
    cancel.addActionListener(event -> {
        fileSearchCancelled = true;
        ((JButton) event.getSource()).setEnabled(false);
    });
    final JDialog progressDialog = new JDialog(progressParent, title, false);
    bar.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
    bar.setIndeterminate(true);
    if (includeCancelButton) {
        progressDialog.add(cancel, BorderLayout.SOUTH);
    }
    progressDialog.add(new JLabel(message), BorderLayout.NORTH);
    progressDialog.add(bar, BorderLayout.CENTER);
    progressDialog.pack();
    progressDialog.setLocationRelativeTo(null);
    progressDialog.setVisible(true);
    return progressDialog;
}

From source file:net.phyloviz.project.action.LoadDataSetAction.java

private JDialog createLoadingDialog() {
    JDialog d = new JDialog(WindowManager.getDefault().getMainWindow(), null, true);
    d.setLayout(new GridBagLayout());
    JPanel panel = new JPanel();
    JLabel jlabel = new JLabel("Loading DataSet.....");
    jlabel.setFont(new Font("Verdana", 1, 14));
    panel.add(jlabel);/* w  ww  .j  av  a  2s .c  o  m*/
    d.add(panel, new GridBagConstraints());
    d.setSize(200, 50);
    d.setLocationRelativeTo(null);
    d.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
    return d;
}

From source file:es.emergya.ui.base.Message.java

private void inicializar(final String texto) {
    log.trace("inicializar(" + texto + ")");
    final Message message_ = this;

    SwingUtilities.invokeLater(new Runnable() {

        @Override/*from  ww w  . jav a 2  s  .  com*/
        public void run() {
            log.trace("Sacamos un nuevo mensaje: " + texto);
            JDialog frame = new JDialog(window.getFrame(), true);
            frame.setUndecorated(true);
            frame.getContentPane().setBackground(Color.WHITE);
            frame.setLocation(150, window.getHeight() - 140);
            frame.setSize(new Dimension(window.getWidth() - 160, 130));
            frame.setName("Incoming Message");
            frame.setBackground(Color.WHITE);
            frame.getRootPane().setBorder(new MatteBorder(4, 4, 4, 4, color));

            frame.setLayout(new BorderLayout());
            if (font != null)
                frame.setFont(font);

            JLabel icon = new JLabel(new ImageIcon(this.getClass().getResource("/images/button-ok.png")));
            icon.setToolTipText("Cerrar");

            icon.removeMouseListener(null);
            icon.addMouseListener(new Cerrar(frame, message_));

            JLabel text = new JLabel(texto);
            text.setBackground(Color.WHITE);
            text.setForeground(Color.BLACK);
            frame.add(text, BorderLayout.WEST);
            frame.add(icon, BorderLayout.EAST);

            frame.setVisible(true);
        }
    });
}

From source file:com.net2plan.gui.GUINet2Plan.java

private void showKeyCombinations() {
    Component component = container.getComponent(0);
    if (!(component instanceof IGUIModule)) {
        ErrorHandling.showErrorDialog("No tool is active", "Unable to show key associations");
        return;// w w w.ja v  a 2  s  . c  o  m
    }

    final JDialog dialog = new JDialog();
    dialog.setTitle("Key combinations");
    SwingUtils.configureCloseDialogOnEscape(dialog);
    dialog.setModalityType(Dialog.ModalityType.APPLICATION_MODAL);
    dialog.setSize(new Dimension(500, 300));
    dialog.setLocationRelativeTo(null);
    dialog.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE);
    dialog.setLayout(new MigLayout("fill, insets 0 0 0 0"));

    final String[] tableHeader = StringUtils.arrayOf("Key combination", "Action");

    DefaultTableModel model = new ClassAwareTableModel();
    model.setDataVector(new Object[1][tableHeader.length], tableHeader);

    AdvancedJTable table = new AdvancedJTable(model);
    JScrollPane scrollPane = new JScrollPane(table);
    dialog.add(scrollPane, "grow");

    RowSorter<TableModel> sorter = new TableRowSorter<TableModel>(model);
    table.setRowSorter(sorter);

    table.getTableHeader().addMouseListener(new ColumnFitAdapter());

    IGUIModule module = (IGUIModule) component;
    Map<String, KeyStroke> keyCombinations = module.getKeyCombinations();
    if (!keyCombinations.isEmpty()) {
        model.removeRow(0);

        for (Entry<String, KeyStroke> keyCombination : keyCombinations.entrySet()) {
            String description = keyCombination.getKey();
            KeyStroke keyStroke = keyCombination.getValue();
            model.addRow(StringUtils.arrayOf(description, keyStroke.toString().replaceAll(" pressed ", " ")));
        }
    }

    dialog.setVisible(true);
}

From source file:com.net2plan.gui.utils.onlineSimulationPane.OnlineSimulationPane.java

/**
 * Shows the future event list.// w w w .  j  a v a2 s.com
 *
 * @since 0.3.0
 */
public void viewFutureEventList() {
    final JDialog dialog = new JDialog();
    dialog.setTitle("Future event list");
    SwingUtils.configureCloseDialogOnEscape(dialog);
    dialog.setModalityType(Dialog.ModalityType.APPLICATION_MODAL);
    dialog.setSize(new Dimension(500, 300));
    dialog.setLocationRelativeTo(null);
    dialog.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE);
    dialog.setLayout(new MigLayout("fill, insets 0 0 0 0"));

    final String[] tableHeader = StringUtils.arrayOf("Id", "Time", "Priority", "Type", "To module",
            "Custom object");
    Object[][] data = new Object[1][tableHeader.length];

    DefaultTableModel model = new ClassAwareTableModel();
    model.setDataVector(new Object[1][tableHeader.length], tableHeader);

    JTable table = new AdvancedJTable(model);
    RowSorter<TableModel> sorter = new TableRowSorter<TableModel>(model);
    table.setRowSorter(sorter);
    JScrollPane scrollPane = new JScrollPane(table);
    dialog.add(scrollPane, "grow");

    PriorityQueue<SimEvent> futureEventList = simKernel.getSimCore().getFutureEventList().getPendingEvents();
    if (!futureEventList.isEmpty()) {
        int numEvents = futureEventList.size();
        SimEvent[] futureEventList_array = futureEventList.toArray(new SimEvent[numEvents]);
        Arrays.sort(futureEventList_array, futureEventList.comparator());
        data = new Object[numEvents][tableHeader.length];

        for (int eventId = 0; eventId < numEvents; eventId++) {
            //            List<SimAction> actions = futureEventList_array[eventId].getEventActionList();
            Object customObject = futureEventList_array[eventId].getEventObject();
            data[eventId][0] = eventId;
            data[eventId][1] = StringUtils
                    .secondsToYearsDaysHoursMinutesSeconds(futureEventList_array[eventId].getEventTime());
            data[eventId][2] = futureEventList_array[eventId].getEventPriority();
            data[eventId][3] = futureEventList_array[eventId].getEventType();
            data[eventId][4] = futureEventList_array[eventId].getEventDestinationModule().toString();
            data[eventId][5] = customObject == null ? "none" : customObject;
        }
    }

    model.setDataVector(data, tableHeader);
    table.getTableHeader().addMouseListener(new ColumnFitAdapter());
    table.setDefaultRenderer(Double.class, new CellRenderers.NumberCellRenderer());

    dialog.setVisible(true);
}