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();
}
});
}
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);
}
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;
}
}
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");
}
}
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;
}
}
Aggregations