[英]How to add JProgressBar into JDialog
I'm trying to add JProgressBar to JDialog but JProgressBar never show up. 我正在尝试将JProgressBar添加到JDialog,但JProgressBar永远不会显示。 Below is my code. 下面是我的代码。 Any help? 有什么帮助吗?
JDialog downloadingDialog = new JDialog(jbpci ,"Start donwloading...");
JProgressBar progressBar = new JProgressBar(JProgressBar.HORIZONTAL);
progressBar.setIndeterminate(true);
downloadingDialog.setLayout(new FlowLayout(FlowLayout.LEFT));
downloadingDialog.add(progressBar);
downloadingDialog.setLocation(jbpci.getLocationOnScreen().x + jbpci.getWidth() / 2, jbpci.getLocationOnScreen().y + jbpci.getHeight() / 2);
downloadingDialog.setSize(300, 100);
downloadingDialog.setVisible(true);
I wrapped your code in a class and removed references to jbpci, and it works fine: 我将您的代码包装在一个类中,并删除了对jbpci的引用,并且工作正常:
import javax.swing.*;
import java.awt.*;
public class t {
public static void main(String[] args) {
JDialog downloadingDialog = new JDialog((JFrame)null ,"Start donwloading...");
JProgressBar progressBar = new JProgressBar(JProgressBar.HORIZONTAL);
progressBar.setIndeterminate(true);
downloadingDialog.setLayout(new FlowLayout(FlowLayout.LEFT));
downloadingDialog.add(progressBar);
downloadingDialog.setSize(300, 100);
downloadingDialog.setVisible(true);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.