Multiple input in JOptionPane.showInputDialog

Yes. You know that you can put any Object into the Object parameter of most JOptionPane.showXXX methods, and often that Object happens to be a JPanel. In your situation, perhaps you could use a JPanel that has several JTextFields in it: import javax.swing.*; public class JOptionPaneMultiInput { public static void main(String[] args) { JTextField xField … Read more

Why JScrollPane in JOptionPane not showing all its content?

As shown in this related example, you can override the viewport’s preferred size. import java.awt.Dimension; import java.awt.EventQueue; import javax.swing.GroupLayout; import javax.swing.JLabel; import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTextField; import javax.swing.SwingConstants; /** * @see https://stackoverflow.com/a/14858272/230513 * @see https://stackoverflow.com/a/8504753/230513 * @see https://stackoverflow.com/a/14011536/230513 */ public class DynamicGroupLayout { private static final int NUM = 30; private JTextField[] … Read more

Text wrap in JOptionPane?

A JOptionPane will use a JLabel to display text by default. A label will format HTML. Set the maximum width in CSS. JOptionPane.showMessageDialog( this, “<html><body><p style=”width: 200px;”>”+exp.getMessage()+”</p></body></html>”, “Error”, JOptionPane.ERROR_MESSAGE); More generally, see How to Use HTML in Swing Components, as well as this simple example of using HTML in JLabel.

Display indeterminate JProgressBar while batch file runs

You can run a ProcessBuilder in the background of a SwingWorker, as shown below, to get both output and a progress bar. import java.awt.BorderLayout; import java.awt.EventQueue; import java.awt.event.*; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import javax.swing.*; /** * @se http://stackoverflow.com/a/20603012/230513 * @see http://stackoverflow.com/a/17763395/230513 */ public class SwingWorkerExample { private final JLabel statusLabel = new JLabel(“Status: … Read more