Tabnine Logo
JOptionPane
Code IndexAdd Tabnine to your IDE (free)

How to use
JOptionPane
in
javax.swing

Best Java code snippets using javax.swing.JOptionPane (Showing top 20 results out of 9,513)

Refine searchRefine arrow

  • Container
  • Window
  • JFrame
  • JPanel
  • JButton
  • JLabel
  • AbstractButton
origin: stackoverflow.com

 import javax.swing.*;

public class FixedWidthLabel {

  public static void main(String[] srgs) {
    final String s = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean eu nulla urna. Donec sit amet risus nisl, a porta enim. Quisque luctus, ligula eu scelerisque gravida, tellus quam vestibulum urna, ut aliquet sapien purus sed erat. Pellentesque consequat vehicula magna, eu aliquam magna interdum porttitor. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Sed sollicitudin sapien non leo tempus lobortis. Morbi semper auctor ipsum, a semper quam elementum a. Aliquam eget sem metus.";
    final String html1 = "<html><body style='width: ";
    final String html2 = "px'>";

    Runnable r = new Runnable() {

      @Override
      public void run() {
        JOptionPane.showMessageDialog(
            null, new JLabel(html1 + "200" + html2 + s));
        JOptionPane.showMessageDialog(
            null, new JLabel(html1 + "300" + html2 + s));
      }
    };
    SwingUtilities.invokeLater(r);
  }
}
origin: stackoverflow.com

 import javax.swing.*;

public class JOptionPaneMultiInput {
  public static void main(String[] args) {
   JTextField xField = new JTextField(5);
   JTextField yField = new JTextField(5);

   JPanel myPanel = new JPanel();
   myPanel.add(new JLabel("x:"));
   myPanel.add(xField);
   myPanel.add(Box.createHorizontalStrut(15)); // a spacer
   myPanel.add(new JLabel("y:"));
   myPanel.add(yField);

   int result = JOptionPane.showConfirmDialog(null, myPanel, 
        "Please Enter X and Y Values", JOptionPane.OK_CANCEL_OPTION);
   if (result == JOptionPane.OK_OPTION) {
     System.out.println("x value: " + xField.getText());
     System.out.println("y value: " + yField.getText());
   }
  }
}
origin: stackoverflow.com

 package experiments;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JOptionPane;

public class CreateDialogFromOptionPane {

  public static void main(final String[] args) {
    final JFrame parent = new JFrame();
    JButton button = new JButton();

    button.setText("Click me to show dialog!");
    parent.add(button);
    parent.pack();
    parent.setVisible(true);

    button.addActionListener(new java.awt.event.ActionListener() {
      @Override
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        String name = JOptionPane.showInputDialog(parent,
            "What is your name?", null);
      }
    });
  }
}
origin: libgdx/libgdx

@Override
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);
  textPanel.add(textField);
  JOptionPane pane = new JOptionPane(panel, JOptionPane.QUESTION_MESSAGE, JOptionPane.OK_CANCEL_OPTION, null, null,
    null);
  pane.setInitialValue(null);
  pane.setComponentOrientation(JOptionPane.getRootFrame().getComponentOrientation());
  placeholderLabel.setBorder(new EmptyBorder(border.getBorderInsets(textField)));
  JDialog dialog = pane.createDialog(null, title);
  pane.selectInitialValue();
  dialog.dispose();
  Object selectedValue = pane.getValue();
origin: stanfordnlp/CoreNLP

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.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[2] = useAnotherEncoding;
 fileFilterDialog.setOptions(options);
 final JDialog dialog = fileFilterDialog.createDialog(null, "Default encoding changed...");
 useNewEncoding.addActionListener(arg0 -> {
  FileTreeModel.setCurEncoding(encoding);
origin: marytts/marytts

private void showProgressPanel(List<ComponentDescription> comps, boolean install) {
  final ProgressPanel pp = new ProgressPanel(comps, install);
  final JOptionPane optionPane = new JOptionPane(pp, JOptionPane.PLAIN_MESSAGE, JOptionPane.DEFAULT_OPTION, null,
      new String[] { "Abort" }, "Abort");
  // optionPane.setPreferredSize(new Dimension(640,480));
  final JDialog dialog = new JDialog((Frame) null, "Progress", false);
  dialog.setContentPane(optionPane);
  optionPane.addPropertyChangeListener(new PropertyChangeListener() {
    public void propertyChange(PropertyChangeEvent e) {
      String prop = e.getPropertyName();
      if (dialog.isVisible() && (e.getSource() == optionPane) && (prop.equals(JOptionPane.VALUE_PROPERTY))) {
        pp.requestExit();
        dialog.setVisible(false);
      }
    }
  });
  dialog.pack();
  dialog.setVisible(true);
  new Thread(pp).start();
}
origin: skylot/jadx

panel.add(makeOtherGroup());
JButton saveBtn = new JButton(NLS.str("preferences.save"));
saveBtn.addActionListener(event -> {
  settings.sync();
  if (needReload) {
    JOptionPane.showMessageDialog(
        this,
        NLS.str("msg.language_changed", settings.getLangLocale()),
JButton cancelButton = new JButton(NLS.str("preferences.cancel"));
cancelButton.addActionListener(event -> {
  JadxSettingsAdapter.fill(settings, startSettings);
JButton resetBtn = new JButton(NLS.str("preferences.reset"));
resetBtn.addActionListener(event -> {
  int res = JOptionPane.showConfirmDialog(
      JadxSettingsWindow.this,
      NLS.str("preferences.reset_message"),
contentPane.add(panel, BorderLayout.CENTER);
contentPane.add(buttonPane, BorderLayout.PAGE_END);
getRootPane().setDefaultButton(saveBtn);
origin: stackoverflow.com

JFrame frame = new JFrame();
JPanel panel = new JPanel();
JLabel label = new JLabel("Loading...");
JProgressBar jpb = new JProgressBar();
jpb.setIndeterminate(false);
int max = 1000;
jpb.setMaximum(max);
panel.add(label);
panel.add(jpb);
frame.add(panel);
frame.pack();
frame.setSize(200,90);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
new Task_IntegerUpdate(jpb, max, label).execute();
  label.setText("Loading " + i + " of " + max);
  try {
    get();
    JOptionPane.showMessageDialog(jpb.getParent(), "Success", "Success", JOptionPane.INFORMATION_MESSAGE);
  } catch (ExecutionException | InterruptedException e) {
    e.printStackTrace();
origin: runelite/runelite

topPanel.removeAll();
mainPanel.removeAll();
topPanelBackButton.addActionListener(e -> openConfigList());
topPanelBackButton.setToolTipText("Back");
topPanel.add(topPanelBackButton, BorderLayout.WEST);
topPanel.add(listItem.createToggleButton(), BorderLayout.EAST);
JLabel title = new JLabel(name);
title.setForeground(Color.WHITE);
title.setToolTipText("<html>" + name + ":<br>" + listItem.getDescription() + "</html>");
topPanel.add(title);
      colorPickerBtn = new JButton("Pick a color");
      colorPickerBtn = new JButton(ColorUtil.toHexColor(existingColor).toUpperCase());
    colorPickerBtn.setFocusable(false);
    colorPickerBtn.setBackground(existingColor);
    colorPickerBtn.addMouseListener(new MouseAdapter()
resetButton.addActionListener((e) ->
  final int result = JOptionPane.showOptionDialog(resetButton, "Are you sure you want to reset this plugin's configuration?",
    "Are you sure?", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE,
    null, new String[]{"Yes", "No"}, "No");
origin: stackoverflow.com

final JFrame frame = new JFrame("Text HIGHLIGHT");
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
JPanel contentPane = new JPanel();
contentPane.setBorder(BorderFactory.createTitledBorder(
    BorderFactory.createEmptyBorder(5, 5, 5, 5), "Highlighter JTextArea"));
contentPane.add(scrollPane);
JButton remHighButton = new JButton("REMOVE HIGHLIGHT");
remHighButton.addActionListener(new ActionListener()
    String input = JOptionPane.showInputDialog(frame, "Please Enter Start Index : "
                        , "Highlighting Options : "
                        , JOptionPane.PLAIN_MESSAGE);
JButton button = new JButton("HIGHLIGHT TEXT");
button.addActionListener(new ActionListener()
      Highlighter highlighter = tarea.getHighlighter();
      int selection = JOptionPane.showConfirmDialog(
                  frame, getOptionPanel(), "Highlight Colour : "
                    , JOptionPane.OK_CANCEL_OPTION
JLabel colourLabel = new JLabel("Select One Colour : ");
cbox = new JComboBox(colourNames);
origin: stackoverflow.com

private JButton    m_multiplyBtn = new JButton("Multiply");
private JButton    m_clearBtn    = new JButton("Clear");
  JPanel content = new JPanel();
  content.setLayout(new FlowLayout());
  content.add(new JLabel("Input"));
  content.add(m_userInputTf);
  content.add(m_multiplyBtn);
  content.add(new JLabel("Total"));
  content.add(m_totalTf);
  content.add(m_clearBtn);
  this.setContentPane(content);
  this.pack();
  this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  JOptionPane.showMessageDialog(this, errMessage);
  m_multiplyBtn.addActionListener(mal);
  m_clearBtn.addActionListener(cal);
origin: stackoverflow.com

private WebEngine engine;
private JFrame frame = new JFrame();
private JPanel panel = new JPanel(new BorderLayout());
private JLabel lblStatus = new JLabel();
  btnGo.addActionListener(al);
  txtURL.addActionListener(al);
  progressBar.setStringPainted(true);
  panel.add(statusBar, BorderLayout.SOUTH);
  frame.getContentPane().add(panel);
                SwingUtilities.invokeLater(new Runnable() {
                  @Override public void run() {
                    JOptionPane.showMessageDialog(
                        panel,
                        (value != null) ?
  frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  frame.pack();
  frame.setVisible(true);
origin: stackoverflow.com

Runnable r = new Runnable() {
 public void run() {
  final JFrame f = new JFrame("Test Screenshot");
    InputEvent.CTRL_DOWN_MASK
   ));
  screenshot.addActionListener(
   new ActionListener(){
    public void actionPerformed(ActionEvent ae) {
     BufferedImage img = getScreenShot(
      f.getContentPane() );
     JOptionPane.showMessageDialog(
      null,
      new JLabel(
       new ImageIcon(
        img.getScaledInstance(
  JMenuBar mb = new JMenuBar();
  mb.add(menu);
  f.setJMenuBar(mb);
  f.setContentPane( p );
  f.pack();
  f.setLocationRelativeTo(null);
  f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  f.setVisible(true);
origin: libgdx/libgdx

void generate () {
  final String name = ui.form.nameText.getText().trim();
  if (name.length() == 0) {
    JOptionPane.showMessageDialog(this, "Please enter a project name.");
    return;
    JOptionPane.showMessageDialog(this, "Please enter a package name.");
    return;
    JOptionPane.showMessageDialog(this, "Invalid package name");
    return;
    JOptionPane.showMessageDialog(this, "Please enter a game class name.");
    return;
    JOptionPane.showMessageDialog(this, "Please enter a destination directory.");
    return;
    JOptionPane.showMessageDialog(this, "Please enter your Android SDK's path");
    return;
        .showMessageDialog(this,
            "Your Android SDK path doesn't contain an SDK! Please install the Android SDK, including all platforms and build tools!");
    return;
    JOptionPane.showMessageDialog(this, "HTML sub-projects are not supported by the selected programming language.");
    ui.form.gwtCheckBox.setSelected(false);
    modules.remove(ProjectType.HTML);
    int value = JOptionPane.showConfirmDialog(this, "The destination is not empty, do you want to overwrite?", "Warning!", JOptionPane.YES_NO_OPTION);
origin: stackoverflow.com

java.awt.GridBagConstraints gridBagConstraints;
jLabel1 = new javax.swing.JLabel();
jTextField1 = new javax.swing.JTextField();
jLabel2 = new javax.swing.JLabel();
jButton1 = new javax.swing.JButton();
gridBagConstraints.gridy = 2;
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
getContentPane().add(jTextField1, gridBagConstraints);
jButton1.setText("Login");
jButton1.addActionListener(new java.awt.event.ActionListener() {
  public void actionPerformed(java.awt.event.ActionEvent evt) {
    jButton1ActionPerformed(evt);
pack();
setVisible(true);
jTextField1.selectAll();
jTextField1.requestFocus();
        JOptionPane.showMessageDialog(null, "Welcome user!");
origin: stackoverflow.com

SwingUtilities.invokeLater( new Runnable() {
  public void run() {
    JPanel gui = new JPanel(new BorderLayout(3,3));
    final JPanel panel = new JPanel(new GridLayout(0,1));
    final JScrollPane scroll = new JScrollPane(panel);
    scroll.setPreferredSize(new Dimension(80,100));
    gui.add(scroll, BorderLayout.CENTER);
    JButton addLabel = new JButton("Add Label");
    gui.add(addLabel, BorderLayout.NORTH);
    ActionListener listener = new ActionListener() {
      int counter = 0;
      public void actionPerformed(ActionEvent ae) {
        panel.add(new JLabel("Label " + ++counter));
        panel.revalidate();
        int height = (int)panel.getPreferredSize().getHeight();
    addLabel.addActionListener(listener);
    JOptionPane.showMessageDialog(null, gui);
origin: stackoverflow.com

 @Override
 public void run() {
  JFrame testFrame = new JFrame( "FormattedTextFieldDemo" );
  integerFormattedTextField.setColumns( 20 );
  testFrame.add( createButtonPanel( integerFormattedTextField ), BorderLayout.NORTH );
  integerFormattedTextField.addPropertyChangeListener( "value", updateTextAreaListener );
  testFrame.add( new JScrollPane( textArea ), BorderLayout.CENTER );
  testFrame.setDefaultCloseOperation( WindowConstants.DISPOSE_ON_CLOSE );
  testFrame.pack();
  testFrame.setVisible( true );
JPanel panel = new JPanel( new BorderLayout(  ) );
panel.add( aTextField, BorderLayout.WEST );
  JOptionPane.showMessageDialog( null, "The current value is [" + aTextField.getValue() + "] of class [" + aTextField.getValue().getClass() + "]" );
panel.add( new JButton( action ), BorderLayout.EAST );
return panel;
origin: stackoverflow.com

JPanel gui = new JPanel(new GridLayout(2,0,5,5));
gui.setBorder(new EmptyBorder(10,10,10,10));
gui.setBackground(Color.RED);
AbstractBorder brdrRight = new TextBubbleBorder(Color.BLACK,2,16,16,false);
JLabel l1 = new JLabel("Label 1");
l1.setBorder(brdrRight);
gui.add(l1);
JLabel l2 = new JLabel("Label 2");
l2.setBorder(brdrLeft);
l2.setBackground(Color.YELLOW);
l2.setOpaque(true);
gui.add(l2);
JPanel p1 = new JPanel();
p1.add(new JLabel("Panel 1"));
p1.setBorder(brdrRight);
p1.setOpaque(false);
gui.add(p1);
JPanel p2 = new JPanel();
p2.add(new JLabel("Panel 2"));
p2.setBorder(brdrLeft);
gui.add(p2);
JOptionPane.showMessageDialog(null, gui);
origin: kiegroup/optaplanner

@Override
public void actionPerformed(ActionEvent e) {
  JPanel listFieldsPanel = new JPanel(new GridLayout(1, 2));
  listFieldsPanel.add(new JLabel("Computer:"));
  List<CloudComputer> computerList = getSolution().getComputerList();
  // Add 1 to array size to add null, which makes the entity unassigned
  JComboBox computerListField = new JComboBox(
      computerList.toArray(new Object[computerList.size() + 1]));
  LabeledComboBoxRenderer.applyToComboBox(computerListField);
  computerListField.setSelectedItem(process.getComputer());
  listFieldsPanel.add(computerListField);
  int result = JOptionPane.showConfirmDialog(CloudBalancingPanel.this.getRootPane(), listFieldsPanel,
      "Select computer", JOptionPane.OK_CANCEL_OPTION);
  if (result == JOptionPane.OK_OPTION) {
    CloudComputer toComputer = (CloudComputer) computerListField.getSelectedItem();
    if (process.getComputer() != toComputer) {
      solutionBusiness.doChangeMove(process, "computer", toComputer);
    }
    solverAndPersistenceFrame.resetScreen();
  }
}
origin: stackoverflow.com

final JFrame frame = new JFrame();
frame.setPreferredSize(new Dimension(600, 400));
final JToolBar toolBar = new JToolBar();
popup.add(new JMenuItem(new AbstractAction("Option 1") {
  public void actionPerformed(ActionEvent e) {
    JOptionPane.showMessageDialog(frame, "Option 1 selected");
    JOptionPane.showMessageDialog(frame, "Option 2 selected");
final JButton button = new JButton("Options");
button.addMouseListener(new MouseAdapter() {
  public void mousePressed(MouseEvent e) {
toolBar.add(button);
frame.getContentPane().add(toolBar, BorderLayout.NORTH);
frame.pack();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
javax.swingJOptionPane

Most used methods

  • showMessageDialog
  • showConfirmDialog
  • showInputDialog
  • showOptionDialog
  • <init>
  • createDialog
  • getValue
  • getRootFrame
  • getFrameForComponent
  • addPropertyChangeListener
  • setValue
  • showInternalMessageDialog
  • setValue,
  • showInternalMessageDialog,
  • setOptions,
  • setMessage,
  • setMessageType,
  • showInternalConfirmDialog,
  • selectInitialValue,
  • setOptionType,
  • setInitialValue,
  • getOptions

Popular in Java

  • Parsing JSON documents to java classes using gson
  • getApplicationContext (Context)
  • getOriginalFilename (MultipartFile)
    Return the original filename in the client's filesystem.This may contain path information depending
  • getSupportFragmentManager (FragmentActivity)
  • Color (java.awt)
    The Color class is used to encapsulate colors in the default sRGB color space or colors in arbitrary
  • Container (java.awt)
    A generic Abstract Window Toolkit(AWT) container object is a component that can contain other AWT co
  • GregorianCalendar (java.util)
    GregorianCalendar is a concrete subclass of Calendarand provides the standard calendar used by most
  • TimerTask (java.util)
    The TimerTask class represents a task to run at a specified time. The task may be run once or repeat
  • JPanel (javax.swing)
  • LoggerFactory (org.slf4j)
    The LoggerFactory is a utility class producing Loggers for various logging APIs, most notably for lo
  • Top Sublime Text plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now