Example usage for javax.swing JProgressBar setStringPainted

List of usage examples for javax.swing JProgressBar setStringPainted

Introduction

In this page you can find the example usage for javax.swing JProgressBar setStringPainted.

Prototype

@BeanProperty(visualUpdate = true, description = "Whether the progress bar should render a string.")
public void setStringPainted(boolean b) 

Source Link

Document

Sets the value of the stringPainted property, which determines whether the progress bar should render a progress string.

Usage

From source file:Main.java

public static void main(String args[]) throws Exception {
    JFrame frame = new JFrame("ProgressBars");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JProgressBar dJProgressBar = new JProgressBar();
    dJProgressBar.setValue(100);/*from  w w w .j a v  a2 s . c  o m*/
    dJProgressBar.setBorderPainted(false);
    dJProgressBar.setString("Ack");
    dJProgressBar.setStringPainted(true);

    frame.add(dJProgressBar, BorderLayout.WEST);
    frame.setSize(300, 200);
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JProgressBar bar = new JProgressBar(JProgressBar.VERTICAL);
    bar.setEnabled(true);/*from   w ww  .j a va  2 s  .c  om*/

    bar.setBackground(Color.YELLOW);
    bar.setForeground(Color.GREEN);

    bar.setStringPainted(true);
    bar.setString("2000 g");
    bar.setValue(65);
    frame.setLayout(new BorderLayout());
    frame.add(bar, BorderLayout.CENTER);
    frame.setSize(500, 400);
    frame.setVisible(true);
}

From source file:MainClass.java

public static void main(String args[]) throws Exception {
    JFrame frame = new JFrame("ProgressBars");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JProgressBar dJProgressBar = new JProgressBar(JProgressBar.VERTICAL);
    dJProgressBar.setValue(100);//from   ww w  . j a v  a  2  s  .c o m
    dJProgressBar.setBorderPainted(false);
    dJProgressBar.setString("Ack");
    dJProgressBar.setStringPainted(true);

    frame.add(dJProgressBar, BorderLayout.WEST);
    frame.setSize(300, 200);
    frame.setVisible(true);
}

From source file:SplashScreenTest.java

/**
 * This method displays a frame with the same image as the splash screen.
 *//*from   w  w w  .j  a  v  a2  s.com*/
private static void init2() {
    final Image img = Toolkit.getDefaultToolkit().getImage(splash.getImageURL());

    final JFrame splashFrame = new JFrame();
    splashFrame.setUndecorated(true);

    final JPanel splashPanel = new JPanel() {
        public void paintComponent(Graphics g) {
            g.drawImage(img, 0, 0, null);
        }
    };

    final JProgressBar progressBar = new JProgressBar();
    progressBar.setStringPainted(true);
    splashPanel.setLayout(new BorderLayout());
    splashPanel.add(progressBar, BorderLayout.SOUTH);

    splashFrame.add(splashPanel);
    splashFrame.setBounds(splash.getBounds());
    splashFrame.setVisible(true);

    new SwingWorker<Void, Integer>() {
        protected Void doInBackground() throws Exception {
            try {
                for (int i = 0; i <= 100; i++) {
                    publish(i);
                    Thread.sleep(100);
                }
            } catch (InterruptedException e) {
            }
            return null;
        }

        protected void process(List<Integer> chunks) {
            for (Integer chunk : chunks) {
                progressBar.setString("Loading module " + chunk);
                progressBar.setValue(chunk);
                splashPanel.repaint(); // because img is loaded asynchronously
            }
        }

        protected void done() {
            splashFrame.setVisible(false);

            JFrame frame = new JFrame();
            frame.setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setTitle("SplashScreenTest");
            frame.setVisible(true);
        }
    }.execute();
}

From source file:org.duracloud.syncui.SyncUIDriver.java

/**
 * Note: The embedded Jetty server setup below is based on the example configuration in the Eclipse documentation:
 * https://www.eclipse.org/jetty/documentation/9.4.x/embedded-examples.html#embedded-webapp-jsp
 *///from  ww w  .  ja v a  2  s  . c  o m
private static void launchServer(final String url, final CloseableHttpClient client) {
    try {
        final JDialog dialog = new JDialog();
        dialog.setSize(new java.awt.Dimension(400, 75));
        dialog.setModalityType(ModalityType.MODELESS);
        dialog.setTitle("DuraCloud Sync");
        dialog.setLocationRelativeTo(null);

        JPanel panel = new JPanel();
        final JLabel label = new JLabel("Loading...");
        final JProgressBar progress = new JProgressBar();
        progress.setStringPainted(true);

        panel.add(label);
        panel.add(progress);
        dialog.add(panel);
        dialog.setVisible(true);

        port = SyncUIConfig.getPort();
        contextPath = SyncUIConfig.getContextPath();
        Server srv = new Server(port);

        // Setup JMX
        MBeanContainer mbContainer = new MBeanContainer(ManagementFactory.getPlatformMBeanServer());
        srv.addBean(mbContainer);

        ProtectionDomain protectionDomain = org.duracloud.syncui.SyncUIDriver.class.getProtectionDomain();
        String warFile = protectionDomain.getCodeSource().getLocation().toExternalForm();

        log.debug("warfile: {}", warFile);
        WebAppContext context = new WebAppContext();
        context.setContextPath(contextPath);
        context.setWar(warFile);
        context.setExtractWAR(Boolean.TRUE);

        Configuration.ClassList classlist = Configuration.ClassList.setServerDefault(srv);
        classlist.addBefore("org.eclipse.jetty.webapp.JettyWebXmlConfiguration",
                "org.eclipse.jetty.annotations.AnnotationConfiguration");

        context.setAttribute("org.eclipse.jetty.server.webapp.ContainerIncludeJarPattern",
                ".*/[^/]*servlet-api-[^/]*\\.jar$|.*/javax.servlet.jsp.jstl-.*\\.jar$|.*/[^/]*taglibs.*\\.jar$");

        srv.setHandler(context);

        new Thread(new Runnable() {
            @Override
            public void run() {
                createSysTray(url, srv);

                while (true) {
                    if (progress.getValue() < 100) {
                        progress.setValue(progress.getValue() + 3);
                    }

                    sleep(2000);
                    if (isAppRunning(url, client)) {
                        break;
                    }
                }

                progress.setValue(100);

                label.setText("Launching browser...");
                launchBrowser(url);
                dialog.setVisible(false);
            }
        }).start();

        srv.start();

        srv.join();
    } catch (Exception e) {
        log.error("Error launching server: " + e.getMessage(), e);
    }
}

From source file:Main.java

public Main() {
    super(new BorderLayout());
    JProgressBar progressBar = new JProgressBar(0, 100);
    progressBar.setValue(0);/*from  w  w w .  ja va  2s  .c om*/
    progressBar.setStringPainted(true);

    taskOutput = new JTextArea(5, 20);
    taskOutput.setEditable(false);

    startButton = new JButton("Start");
    startButton.setActionCommand("start");
    startButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent ae) {
            startButton.setEnabled(false);
            setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));

            final Task task = new Task();
            task.addPropertyChangeListener(new PropertyChangeListener() {
                @Override
                public void propertyChange(PropertyChangeEvent pce) {
                    if ("progress".equals(pce.getPropertyName())) {
                        int progress = (Integer) pce.getNewValue();
                        progressBar.setValue(progress);
                        taskOutput.append(String.format("Completed %d%% of task.\n", task.getProgress()));
                    }
                }
            });
            task.execute();
        }
    });

    JPanel panel = new JPanel();
    panel.add(startButton);
    panel.add(progressBar);

    add(panel, BorderLayout.PAGE_START);
    add(new JScrollPane(taskOutput), BorderLayout.CENTER);

}

From source file:Main.java

private JProgressBar makeProgressBar(int min, int max) {
    JProgressBar progressBar1 = new JProgressBar();
    progressBar1.setMinimum(min);/*  w w  w  .j  a v  a  2  s.  co m*/
    progressBar1.setMaximum(max);
    progressBar1.setStringPainted(true);
    progressBar1.setBorderPainted(true);
    getContentPane().add(progressBar1);
    return progressBar1;
}

From source file:com.ecrimebureau.File.Hash.java

public Hash(JInternalFrame jInternalFrame, JTextArea jTA, String alg, JProgressBar jProgressBar) {
    this.jTA = jTA;
    this.algorithim = alg;
    this.path = path;
    this.jProgressBar = jProgressBar;
    jProgressBar.setStringPainted(true);
    this.jInternalFrame = jInternalFrame;
    jProgressBar.setMinimum(0);//  www . j  a v a 2s . c  om

    jProgressBar.setValue(jProgressBar.getMinimum()); //
}

From source file:com.swg.parse.docx.OpenFolderAction.java

@Override
public void actionPerformed(ActionEvent e) {

    JFileChooser fc = new JFileChooser();
    fc.setCurrentDirectory(new File("C:/"));
    fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    if (selectedFile != null) {
        fc.setSelectedFile(selectedFile);
    }/* w  ww. j  a  v  a 2 s  . com*/

    int returnVal = fc.showDialog(WindowManager.getDefault().getMainWindow(), "Extract Data");

    JFrame jf = new JFrame("Progress Bar");
    Container Jcontent = jf.getContentPane();
    JProgressBar progressBar = new JProgressBar();
    progressBar.setValue(0);
    progressBar.setStringPainted(true);
    Jcontent.add(progressBar, BorderLayout.NORTH);
    jf.setSize(300, 60);
    jf.setVisible(true);

    //we needed a new thread for a functional progress bar on the JFrame
    new Thread(new Runnable() {
        public void run() {

            if (returnVal == JFileChooser.APPROVE_OPTION) {

                File file = fc.getSelectedFile();
                selectedFile = file;

                FileFilter fileFilter = new WildcardFileFilter("*.docx");
                File[] files = selectedFile.listFiles(fileFilter);
                double cnt = 0, cnt2 = 0; //number of how many .docx is in the folder
                for (File f : files) {
                    if (!f.getAbsolutePath().contains("~"))
                        cnt2++;
                }

                for (File f : files) {
                    cnt++;
                    pathToTxtFile = f.getAbsolutePath().replace(".docx", ".txt");
                    TxtFile = new File(pathToTxtFile);

                    //----------------------------------------------------
                    String zipFilePath = "C:\\Users\\fja2\\Desktop\\junk\\Test\\test.zip";
                    String destDirectory = "C:\\Users\\fja2\\Desktop\\junk\\Test " + cnt;
                    UnzipUtility unzipper = new UnzipUtility();
                    try {
                        File zip = new File(zipFilePath);
                        File directory = new File(destDirectory);
                        FileUtils.copyFile(f, zip);
                        unzipper.UnzipUtility(zip, directory);

                        zip.delete();

                        String mediaPath = destDirectory + "/word/media/";
                        File mediaDir = new File(mediaPath);

                        for (File fil : mediaDir.listFiles()) {
                            FileUtils.copyFile(fil, new File("C:\\Users\\PXT1\\Desktop\\test\\Pictures\\"
                                    + f.getName() + "\\" + fil.getName()));
                        }

                        FileUtils.deleteDirectory(directory);

                    } catch (Exception ex) {
                        ex.printStackTrace();
                    }
                    //----------------------------------------------------

                    //if the txt file doesn't exist, it tries to convert whatever 
                    //can be the txt into the actual txt.
                    if (!TxtFile.exists()) {
                        pathToTxtFile = f.getAbsolutePath().replace(".docx", "");
                        TxtFile = new File(pathToTxtFile);
                        pathToTxtFile += ".txt";
                        TxtFile.renameTo(new File(pathToTxtFile));
                        TxtFile = new File(pathToTxtFile);
                    }

                    String content = "";
                    String POIContent = "";

                    try {
                        content = readTxtFile();
                        version = DetermineVersion(content);
                        NewExtract ext = new NewExtract();
                        ext.extract(content, f.getAbsolutePath(), version, (int) cnt);

                    } catch (FileNotFoundException ex) {
                        Exceptions.printStackTrace(ex);
                    } catch (IOException ex) {
                        Exceptions.printStackTrace(ex);
                    } catch (ParseException ex) {
                        Exceptions.printStackTrace(ex);
                    }

                    double tempProg = (cnt / cnt2) * 100;
                    progressBar.setValue((int) tempProg);
                    System.gc();
                }

            } else {
                //do nothing
            }
        }
    }).start();

    System.gc();

}

From source file:marytts.tools.voiceimport.DatabaseImportMain.java

/**
 * Run the selected components in a different thread.
 *
 *///from ww  w . ja  v a2 s .c om
protected void runSelectedComponents() {
    new Thread("RunSelectedComponentsThread") {
        public void run() {
            try {
                runButton.setEnabled(false);
                for (int i = 0; i < components.length; i++) {
                    if (checkboxes[i].isSelected()) {
                        boolean success = false;
                        Container parent = checkboxes[i].getParent();
                        final JProgressBar progress = new JProgressBar();
                        final VoiceImportComponent oneComponent = components[i];
                        if (oneComponent.getProgress() != -1) {
                            progress.setStringPainted(true);
                            new Thread("ProgressThread") {
                                public void run() {
                                    int percent = 0;
                                    while (progress.isVisible()) {
                                        progress.setValue(percent);
                                        try {
                                            Thread.sleep(500);
                                        } catch (InterruptedException ie) {
                                        }
                                        percent = oneComponent.getProgress();
                                    }
                                }
                            }.start();
                        } else {
                            progress.setIndeterminate(true);
                        }
                        parent.add(progress, BorderLayout.EAST);
                        progress.setVisible(true);
                        parent.validate();
                        try {
                            success = oneComponent.compute();
                        } catch (Exception exc) {
                            checkboxes[i].setBackground(Color.RED);
                            throw new Exception("The component " + checkboxes[i].getText()
                                    + " produced the following exception: ", exc);
                        } finally {
                            checkboxes[i].setSelected(false);
                            progress.setVisible(false);
                        }
                        if (success) {
                            checkboxes[i].setBackground(Color.GREEN);
                        } else {
                            checkboxes[i].setBackground(Color.RED);
                        }
                    }
                }
            } catch (Throwable e) {
                e.printStackTrace();
            } finally {
                runButton.setEnabled(true);
            }

        }
    }.start();
}