Search in sources :

Example 11 with JOptionPane

use of javax.swing.JOptionPane in project libgdx by libgdx.

the class JglfwInput method getTextInput.

public void getTextInput(final TextInputListener listener, final String title, final String text, final String hint) {
    SwingUtilities.invokeLater(new Runnable() {

        public void run() {
            JPanel panel = new JPanel(new FlowLayout());
            JPanel textPanel = new JPanel() {

                public boolean isOptimizedDrawingEnabled() {
                    return false;
                }

                ;
            };
            textPanel.setLayout(new OverlayLayout(textPanel));
            panel.add(textPanel);
            final JTextField textField = new JTextField(20);
            textField.setText(text);
            textField.setAlignmentX(0.0f);
            textPanel.add(textField);
            final JLabel placeholderLabel = new JLabel(hint);
            placeholderLabel.setForeground(Color.GRAY);
            placeholderLabel.setAlignmentX(0.0f);
            textPanel.add(placeholderLabel, 0);
            textField.getDocument().addDocumentListener(new DocumentListener() {

                public void removeUpdate(DocumentEvent event) {
                    this.updated();
                }

                public void insertUpdate(DocumentEvent event) {
                    this.updated();
                }

                public void changedUpdate(DocumentEvent event) {
                    this.updated();
                }

                private void updated() {
                    placeholderLabel.setVisible(textField.getText().length() == 0);
                }
            });
            JOptionPane pane = new JOptionPane(panel, JOptionPane.QUESTION_MESSAGE, JOptionPane.OK_CANCEL_OPTION, null, null, null);
            pane.setComponentOrientation(JOptionPane.getRootFrame().getComponentOrientation());
            pane.selectInitialValue();
            placeholderLabel.setBorder(new EmptyBorder(textField.getBorder().getBorderInsets(textField)));
            JDialog dialog = pane.createDialog(null, title);
            dialog.addWindowFocusListener(new WindowFocusListener() {

                public void windowLostFocus(WindowEvent arg0) {
                }

                public void windowGainedFocus(WindowEvent arg0) {
                    textField.requestFocusInWindow();
                }
            });
            dialog.setVisible(true);
            dialog.dispose();
            Object selectedValue = pane.getValue();
            if (selectedValue != null && (selectedValue instanceof Integer) && (Integer) selectedValue == JOptionPane.OK_OPTION)
                listener.input(textField.getText());
            else
                listener.canceled();
        }
    });
}
Also used : JPanel(javax.swing.JPanel) DocumentListener(javax.swing.event.DocumentListener) FlowLayout(java.awt.FlowLayout) JLabel(javax.swing.JLabel) JTextField(javax.swing.JTextField) DocumentEvent(javax.swing.event.DocumentEvent) JOptionPane(javax.swing.JOptionPane) WindowEvent(java.awt.event.WindowEvent) OverlayLayout(javax.swing.OverlayLayout) EmptyBorder(javax.swing.border.EmptyBorder) JDialog(javax.swing.JDialog) WindowFocusListener(java.awt.event.WindowFocusListener)

Example 12 with JOptionPane

use of javax.swing.JOptionPane in project CoreNLP by stanfordnlp.

the class PreferencesPanel method doEncodingPrompt.

private void doEncodingPrompt(final String encoding, final String oldEncoding) {
    final JPanel encodingPanel = new JPanel();
    encodingPanel.setLayout(new BoxLayout(encodingPanel, BoxLayout.PAGE_AXIS));
    JLabel text = new JLabel("<html>A head finder or tree reader was selected that has the default encoding " + encoding + "; this differs from " + oldEncoding + ", which was being used. If the encoding is changed, all newly loaded" + "treebanks will be read using the new encoding. Choosing an encoding that is not the true encoding of your tree " + "files may cause errors and unexpected behavior.</html>");
    //text.setBorder(BorderFactory.createLineBorder(Color.black));
    text.setAlignmentX(SwingConstants.LEADING);
    JPanel textPanel = new JPanel(new BorderLayout());
    textPanel.setPreferredSize(new Dimension(100, 100));
    textPanel.add(text);
    encodingPanel.add(textPanel);
    encodingPanel.add(Box.createVerticalStrut(5));
    final JOptionPane fileFilterDialog = new JOptionPane();
    fileFilterDialog.setMessage(encodingPanel);
    JButton[] options = new JButton[3];
    JButton useNewEncoding = new JButton("Use " + encoding);
    JButton useOldEncoding = new JButton("Use " + oldEncoding);
    JButton useAnotherEncoding = new JButton("Use encoding...");
    options[0] = useNewEncoding;
    options[1] = useOldEncoding;
    options[2] = useAnotherEncoding;
    fileFilterDialog.setOptions(options);
    final JDialog dialog = fileFilterDialog.createDialog(null, "Default encoding changed...");
    useNewEncoding.addActionListener(arg0 -> {
        FileTreeModel.setCurEncoding(encoding);
        if (setEncoding == null)
            System.out.println("encoding null!!");
        setEncoding.setText(encoding);
        dialog.setVisible(false);
    });
    useOldEncoding.addActionListener(e -> dialog.setVisible(false));
    useAnotherEncoding.addActionListener(e -> {
        dialog.setVisible(false);
        alternateEncodingPrompt(encoding);
    });
    dialog.getRootPane().setDefaultButton(useNewEncoding);
    dialog.pack();
    dialog.setLocationRelativeTo(this);
    dialog.setVisible(true);
}
Also used : JPanel(javax.swing.JPanel) BorderLayout(java.awt.BorderLayout) BoxLayout(javax.swing.BoxLayout) JButton(javax.swing.JButton) JLabel(javax.swing.JLabel) Dimension(java.awt.Dimension) JOptionPane(javax.swing.JOptionPane) JDialog(javax.swing.JDialog)

Example 13 with JOptionPane

use of javax.swing.JOptionPane in project GNS by MobilityFirst.

the class EC2Runner method showDialog.

private static boolean showDialog(String message, final long timeout) {
    try {
        int dialog = JOptionPane.YES_NO_OPTION;
        JOptionPane optionPane = new JOptionPane(message, JOptionPane.QUESTION_MESSAGE, JOptionPane.YES_NO_OPTION);
        final JDialog dlg = optionPane.createDialog("Error");
        new Thread(new Runnable() {

            @Override
            public void run() {
                {
                    ThreadUtils.sleep(timeout);
                    dlg.dispose();
                }
            }
        }).start();
        dlg.setVisible(true);
        int value = ((Integer) optionPane.getValue()).intValue();
        if (value == JOptionPane.YES_OPTION) {
            return true;
        } else {
            return false;
        }
    } catch (RuntimeException e) {
        return true;
    }
}
Also used : JOptionPane(javax.swing.JOptionPane) JDialog(javax.swing.JDialog)

Example 14 with JOptionPane

use of javax.swing.JOptionPane in project jdk8u_jdk by JetBrains.

the class InsetsEncapsulation method run.

@Override
public void run() {
    runTest(new JLabel("hi"));
    runTest(new JMenu());
    runTest(new JTree());
    runTest(new JTable());
    runTest(new JMenuItem());
    runTest(new JCheckBoxMenuItem());
    runTest(new JToggleButton());
    runTest(new JSpinner());
    runTest(new JSlider());
    runTest(Box.createVerticalBox());
    runTest(Box.createHorizontalBox());
    runTest(new JTextField());
    runTest(new JTextArea());
    runTest(new JTextPane());
    runTest(new JPasswordField());
    runTest(new JFormattedTextField());
    runTest(new JEditorPane());
    runTest(new JButton());
    runTest(new JColorChooser());
    runTest(new JFileChooser());
    runTest(new JCheckBox());
    runTest(new JInternalFrame());
    runTest(new JDesktopPane());
    runTest(new JTableHeader());
    runTest(new JLayeredPane());
    runTest(new JRootPane());
    runTest(new JMenuBar());
    runTest(new JOptionPane());
    runTest(new JRadioButton());
    runTest(new JRadioButtonMenuItem());
    runTest(new JPopupMenu());
    runTest(new JScrollBar());
    runTest(new JScrollPane());
    runTest(new JViewport());
    runTest(new JSplitPane());
    runTest(new JTabbedPane());
    runTest(new JToolBar());
    runTest(new JSeparator());
    runTest(new JProgressBar());
    if (!failures.isEmpty()) {
        System.out.println("These classes failed");
        for (final Component failure : failures) {
            System.out.println(failure.getClass());
        }
        throw new RuntimeException("Test failed");
    }
}
Also used : JDesktopPane(javax.swing.JDesktopPane) JTextArea(javax.swing.JTextArea) JRadioButton(javax.swing.JRadioButton) JLayeredPane(javax.swing.JLayeredPane) JTabbedPane(javax.swing.JTabbedPane) JButton(javax.swing.JButton) JProgressBar(javax.swing.JProgressBar) JTableHeader(javax.swing.table.JTableHeader) JTextField(javax.swing.JTextField) JSeparator(javax.swing.JSeparator) JScrollBar(javax.swing.JScrollBar) JTextPane(javax.swing.JTextPane) JToggleButton(javax.swing.JToggleButton) JSlider(javax.swing.JSlider) JMenuItem(javax.swing.JMenuItem) JComponent(javax.swing.JComponent) Component(java.awt.Component) JScrollPane(javax.swing.JScrollPane) JViewport(javax.swing.JViewport) JFormattedTextField(javax.swing.JFormattedTextField) JLabel(javax.swing.JLabel) JRadioButtonMenuItem(javax.swing.JRadioButtonMenuItem) JToolBar(javax.swing.JToolBar) JOptionPane(javax.swing.JOptionPane) JCheckBoxMenuItem(javax.swing.JCheckBoxMenuItem) JPopupMenu(javax.swing.JPopupMenu) JCheckBox(javax.swing.JCheckBox) JTree(javax.swing.JTree) JFileChooser(javax.swing.JFileChooser) JPasswordField(javax.swing.JPasswordField) JTable(javax.swing.JTable) JEditorPane(javax.swing.JEditorPane) JSpinner(javax.swing.JSpinner) JRootPane(javax.swing.JRootPane) JSplitPane(javax.swing.JSplitPane) JColorChooser(javax.swing.JColorChooser) JInternalFrame(javax.swing.JInternalFrame) JMenu(javax.swing.JMenu) JMenuBar(javax.swing.JMenuBar)

Example 15 with JOptionPane

use of javax.swing.JOptionPane in project JMRI by JMRI.

the class BlockTableAction method setDefaultSpeeds.

protected void setDefaultSpeeds(JFrame _who) {
    JComboBox<String> blockSpeedCombo = new JComboBox<String>(speedList);
    blockSpeedCombo.setEditable(true);
    JPanel block = new JPanel();
    block.add(new JLabel(Bundle.getMessage("MakeLabel", Bundle.getMessage("BlockSpeedLabel"))));
    block.add(blockSpeedCombo);
    blockSpeedCombo.removeItem(defaultBlockSpeedText);
    blockSpeedCombo.setSelectedItem(InstanceManager.getDefault(jmri.BlockManager.class).getDefaultSpeed());
    // block of options above row of buttons; gleaned from Maintenance.makeDialog()
    // can be accessed by Jemmy in GUI test
    String title = Bundle.getMessage("BlockSpeedLabel");
    // build JPanel for comboboxes
    JPanel speedspanel = new JPanel();
    speedspanel.setLayout(new BoxLayout(speedspanel, BoxLayout.PAGE_AXIS));
    speedspanel.add(new JLabel(Bundle.getMessage("BlockSpeedSelectDialog")));
    //default LEFT_ALIGNMENT
    block.setAlignmentX(Component.LEFT_ALIGNMENT);
    speedspanel.add(block);
    JOptionPane pane = new JOptionPane(speedspanel, JOptionPane.INFORMATION_MESSAGE, 0, null, new Object[] { Bundle.getMessage("ButtonOK"), Bundle.getMessage("ButtonCancel") });
    //pane.setxxx(value); // Configure more?
    JDialog dialog = pane.createDialog(_who, title);
    dialog.pack();
    dialog.show();
    if (pane.getValue() == null) {
        // pane close button was clicked, check before assigning to retval
        return;
    }
    Object retval = pane.getValue();
    log.debug("Retval = {}", retval.toString());
    // only 2 buttons to choose from, OK = button 2
    if (retval != Bundle.getMessage("ButtonOK")) {
        // Cancel button clicked
        return;
    }
    String speedValue = (String) blockSpeedCombo.getSelectedItem();
    //We will allow the turnout manager to handle checking if the values have changed
    try {
        InstanceManager.getDefault(jmri.BlockManager.class).setDefaultSpeed(speedValue);
    } catch (IllegalArgumentException ex) {
        JOptionPane.showMessageDialog(null, ex.getMessage() + "\n" + speedValue);
        return;
    }
}
Also used : JPanel(javax.swing.JPanel) JComboBox(javax.swing.JComboBox) BoxLayout(javax.swing.BoxLayout) JLabel(javax.swing.JLabel) JOptionPane(javax.swing.JOptionPane) JDialog(javax.swing.JDialog)

Aggregations

JOptionPane (javax.swing.JOptionPane)19 JDialog (javax.swing.JDialog)12 JLabel (javax.swing.JLabel)10 JButton (javax.swing.JButton)6 JPanel (javax.swing.JPanel)6 JTextField (javax.swing.JTextField)5 JComboBox (javax.swing.JComboBox)4 Component (java.awt.Component)3 Dimension (java.awt.Dimension)3 BoxLayout (javax.swing.BoxLayout)3 JCheckBox (javax.swing.JCheckBox)3 BorderLayout (java.awt.BorderLayout)2 ActionEvent (java.awt.event.ActionEvent)2 ActionListener (java.awt.event.ActionListener)2 ArrayList (java.util.ArrayList)2 JCheckBoxMenuItem (javax.swing.JCheckBoxMenuItem)2 JColorChooser (javax.swing.JColorChooser)2 JFrame (javax.swing.JFrame)2 JScrollPane (javax.swing.JScrollPane)2 JTable (javax.swing.JTable)2