[英]JProgressBar Implementation
我开发了一个框架来实时显示图形数据库的实现进度。 为此,我开发了以下框架及其组件。 问题是它在数据库完成后显示。 我如何实现一个JProgressBar,将其底部的代码包围起来?
使用以下命令在主菜单中调用分配了按钮的框架
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
}
});
最好创建一个运行createDB()方法的新线程-避免冻结GUI。 如果要监视该方法的进度,则应(直接或间接)调用progressBar.setValue(int)。 有关更多信息,请参见本教程: http : //docs.oracle.com/javase/tutorial/uiswing/components/progress.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.