javaswingjoptionpanejprogressbar

How do i put a JProgressBar into a JOptionPane in java?


Can anyone tell me how i can make a progress bar go from 1 to 100 percent in a JOptionPane. Its not meant to show anything in particular or have any significance, its just for fun and to simulate something happening in the game to the user. Thanks!


Solution

  • Simple example presented below, I hope that what you looking for.

    public static void main(String[] args) {
        JFrame frame = new JFrame("MessageDialog");
        JOptionPane pane = new JOptionPane();
        pane.setMessage("long message...");
        JProgressBar jProgressBar = new JProgressBar(1, 100);
        jProgressBar.setValue(15);
        pane.add(jProgressBar,1);
        JDialog dialog = pane.createDialog(frame, "Information message");
        dialog.setVisible(true);
        dialog.dispose();
        System.exit(0);
    }