[英]Indeterminate JProgressBar Not displaying String
我正在制作一個病毒掃描程序(開始制作一個),但是我將JProgressBar設置為不確定模式,並且setString(String str)方法不顯示字符串。 如果我不使用不確定的進度條,則字符串顯示正常。
編輯:一些代碼:
import javax.swing.JFrame;
import javax.swing.JProgressBar;
public class Testthing {
public static void main(String[] args) {
JFrame frame = new JFrame();
JProgressBar bar = new JProgressBar(0, 100);
bar.setIndeterminate(true);
bar.setStringPainted(true);
bar.setString("Testing");
frame.add(bar);
frame.setDefaultCloseOperation(3);
frame.setSize(500, 500);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
}
此代碼創建以下框架:
您必須記住將setStringPainted(true)
設置為true。 默認值為false
import java.awt.FlowLayout;
import javax.swing.JFrame;
import javax.swing.JProgressBar;
public class ProgressBar {
public static void main(String[] args) {
JProgressBar progressBar = new JProgressBar();
progressBar.setIndeterminate(true);
progressBar.setString("Loading...");
// This is the important line
progressBar.setStringPainted(true);
JFrame f = new JFrame();
f.setLayout(new FlowLayout());
f.add(progressBar);
f.pack();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setResizable(false);
f.setLocationRelativeTo(null);
f.setVisible(true);
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.