我试图将JProgressBar添加到JDialog,但JProgressBar从未出现过。以下是我的代码。有什么帮助吗?
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);
答案 0 :(得分:0)
我将你的代码包装在一个类中并删除了对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);
}
}