0

I have developed a frame to show in real time the implementation progress of my graph db. For the purpose, I have developed the following frame and its components. The problem is that it is shown after the db is completed. How can I implement a JProgressBar that surrounds the piece of code at the bottom putting it in a tread??

The frame on which the button is allocated is invoked in the main using the following

            EventQueue.invokeLater(new Runnable() {
        public void run() {
            try {

            Interface frame = new Interface();
            frame.setVisible(true);

            } catch (Exception e) {
            e.printStackTrace();
            }

// Button Code

btnNewButton_1.addActionListener(new ActionListener(){
    public void actionPerformed(ActionEvent arg0) {


    // I have created this frame to show the progress of the DB creation
    JFrame converterFrame = new JFrame();
    converterFrame.setVisible(true);
    converterFrame.setBounds(100, 100, 650, 288);
    JPanel contentPane = new JPanel();
    contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
    converterFrame.setContentPane(contentPane);
    contentPane.setLayout(null);
    contentPane.setVisible(true);

    JPanel panelNeo1 = new JPanel();
    panelNeo1.setBackground(SystemColor.text);
    panelNeo1.setBounds(6, 6, 638, 254);
    panelNeo1.setVisible(true);
    contentPane.add(panelNeo1);
    panelNeo1.setLayout(null);

    JLabel labelNeo1 = new JLabel("CSV BORO Converter");
    labelNeo1.setForeground(Color.DARK_GRAY);
    labelNeo1.setBounds(16, 19, 260, 37);
    panelNeo1.add(labelNeo1);
    labelNeo1.setIcon(new ImageIcon(Interface.class.getResource("/javax/swing/plaf/metal/icons/ocean/hardDrive.gif")));
    labelNeo1.setFont(new Font("Lucida Grande", Font.BOLD | Font.ITALIC, 20));
    labelNeo1.setBackground(Color.WHITE);
    labelNeo1.setOpaque(true);
    labelNeo1.setVisible(true);

    JPanel panelNeo2 = new JPanel();
    panelNeo2.setBounds(16, 60, 605, 167);
    panelNeo1.add(panelNeo2);
    panelNeo2.setBackground(SystemColor.textHighlight);
    panelNeo2.setLayout(null);
    panelNeo2.setVisible(true);

    JProgressBar progressBar = new JProgressBar();
    progressBar.setBounds(27, 89, 547, 20);
    panelNeo2.add(progressBar);
    panelNeo2.setVisible(true);

    JLabel labelNeo2 = new JLabel(" Processing: Number of row");
    labelNeo2.setBackground(Color.WHITE);
    labelNeo2.setOpaque(true);
    labelNeo2.setBounds(28, 36, 184, 20);
    panelNeo2.add(labelNeo2);
    labelNeo2.setVisible(true);

    JLabel labelNeo3 = new JLabel("");
    labelNeo3.setBackground(Color.WHITE);
    labelNeo3.setBounds(212, 36, 76, 20);
    labelNeo3.setOpaque(true);
    panelNeo2.add(labelNeo3);
    labelNeo3.setVisible(true);

    JLabel labelNeo4 = new JLabel();
    labelNeo4.setText(String.valueOf(200000));
    labelNeo4.setBackground(Color.WHITE);
    labelNeo4.setBounds(311, 36, 70, 20);
    labelNeo4.setOpaque(true);
    panelNeo2.add(labelNeo4);
    labelNeo4.setVisible(true);

    JLabel labelNeo6 = new JLabel("of");
    labelNeo6.setOpaque(true);
    labelNeo6.setBackground(Color.WHITE);
    labelNeo6.setBounds(288, 36, 23, 20);
    panelNeo2.add(labelNeo6);
    labelNeo6.setVisible(true);


    // I want to put a JProgressBar that surround the following function

            createDB();

                    // In addition I would like to set in my frame a value 
                    // coming from my function and set it in labelNeo3.setText(value)

    //End of Code progress bar          

    }
});
mKorbel
  • 109,525
  • 20
  • 134
  • 319
QGA
  • 3,114
  • 7
  • 39
  • 62
  • 1
    for better help sooner post an [SSCCE](http://sscce.org/), short, runnable, compilable, by cut-off, removing bunch of useless JComponents and add clear description about your intentions with JProgressBar – mKorbel Aug 05 '13 at 12:23

1 Answers1

0

It is better to create a new thread running createDB() method - to avoid freezing the GUI. If you want to monitor the progress of that method, it should call (directly or indirectly) progressBar.setValue(int). For more information look at this tutorial: http://docs.oracle.com/javase/tutorial/uiswing/components/progress.html

pkalinow
  • 1,619
  • 1
  • 17
  • 43