创建垂直进度条的 Java 程序
要创建垂直进度条,请使用以下属性 −
JProgressBar.VERTICAL
按以下方式设置 −
JProgressBar progressBar = new JProgressBar(JProgressBar.VERTICAL,0, 1000);
以下是创建垂直进度条的示例 −
示例
package my; import java.awt.Color; import javax.swing.*; public class SwingDemo extends JFrame { JProgressBar progressBar; int i = 0; SwingDemo() { progressBar = new JProgressBar(JProgressBar.VERTICAL,0, 1000); progressBar.setBounds(70, 50, 120, 30); progressBar.setValue(0); progressBar.setStringPainted(true); add(progressBar); setSize(550, 150); setLayout(null); } public void inc() { while (i <= 1000) { progressBar.setValue(i); i = i + 50; try { Thread.sleep(100); } catch (Exception e) {} } } public static void main(String[] args) { SwingDemo s = new SwingDemo(); s.setVisible(true); s.inc(); } }
输出
广告