0

我开发了一个框架来实时显示我的图形数据库的实施进度。为此,我开发了以下框架及其组件。问题是它在数据库完成后显示。我怎样才能实现一个 JProgressBar,它围绕底部的一段代码,把它放在一个踏板上?

分配按钮的框架在 main 中使用以下方法调用

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

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

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

// 按钮代码

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          

    }
});
4

1 回答 1

0

最好创建一个运行 createDB() 方法的新线程 - 以避免冻结 GUI。如果要监视该方法的进度,则应(直接或间接)调用progressBar.setValue(int)。有关更多信息,请查看本教程:http ://docs.oracle.com/javase/tutorial/uiswing/components/progress.html

于 2013-08-05T12:45:36.627 回答