下面列出了javax.swing.JProgressBar#setValue ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private static void showUI(){
sFrame = new JFrame();
JProgressBar progressBar = new JProgressBar();
progressBar.setVisible(false);
progressBar.setIndeterminate(false);
progressBar.setIndeterminate(true);
progressBar.setIndeterminate(false);
progressBar.setValue(10);
progressBar.setString("Progress");
sFrame.add(progressBar);
sProgressBar = new WeakReference<>(progressBar);
sFrame.setSize(200,200);
sFrame.setVisible(true);
}
private static boolean showUpgradeDialog (final File source, String note) {
Util.setDefaultLookAndFeel();
JPanel panel = new JPanel(new BorderLayout());
panel.add(new AutoUpgradePanel (source.getAbsolutePath (), note), BorderLayout.CENTER);
JProgressBar progressBar = new JProgressBar(0, 100);
progressBar.setValue(0);
progressBar.setStringPainted(true);
progressBar.setIndeterminate(true);
panel.add(progressBar, BorderLayout.SOUTH);
progressBar.setVisible(false);
JButton bYES = new JButton("Yes");
bYES.setMnemonic(KeyEvent.VK_Y);
JButton bNO = new JButton("No");
bNO.setMnemonic(KeyEvent.VK_N);
JButton[] options = new JButton[] {bYES, bNO};
JOptionPane p = new JOptionPane (panel, JOptionPane.QUESTION_MESSAGE, JOptionPane.YES_NO_OPTION, null, options, bYES);
JDialog d = Util.createJOptionProgressDialog(p, NbBundle.getMessage (AutoUpgrade.class, "MSG_Confirmation_Title"), source, progressBar);
d.setVisible (true);
return new Integer (JOptionPane.YES_OPTION).equals (p.getValue ());
}
private void init( ProgressMonitor monitor ) {
this.monitor = monitor;
progressBar = new JProgressBar(0, monitor.getTotal());
if (monitor.isIndeterminate())
progressBar.setIndeterminate(true);
else
progressBar.setValue(monitor.getCurrent());
statusLabel.setText(monitor.getStatus());
JPanel contents = (JPanel) getContentPane();
contents.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
contents.add(statusLabel, BorderLayout.NORTH);
contents.add(progressBar);
setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
monitor.addChangeListener(this);
}
private static void showUI(){
sFrame = new JFrame();
JProgressBar progressBar = new JProgressBar();
progressBar.setVisible(false);
progressBar.setIndeterminate(false);
progressBar.setIndeterminate(true);
progressBar.setIndeterminate(false);
progressBar.setValue(10);
progressBar.setString("Progress");
sFrame.add(progressBar);
sProgressBar = new WeakReference<>(progressBar);
sFrame.setSize(200,200);
sFrame.setVisible(true);
}
private static void showUI(){
sFrame = new JFrame();
JProgressBar progressBar = new JProgressBar();
progressBar.setVisible(false);
progressBar.setIndeterminate(false);
progressBar.setIndeterminate(true);
progressBar.setIndeterminate(false);
progressBar.setValue(10);
progressBar.setString("Progress");
sFrame.add(progressBar);
sProgressBar = new WeakReference<>(progressBar);
sFrame.setSize(200,200);
sFrame.setVisible(true);
}
private static void showUI(){
sFrame = new JFrame();
JProgressBar progressBar = new JProgressBar();
progressBar.setVisible(false);
progressBar.setIndeterminate(false);
progressBar.setIndeterminate(true);
progressBar.setIndeterminate(false);
progressBar.setValue(10);
progressBar.setString("Progress");
sFrame.add(progressBar);
sProgressBar = new WeakReference<>(progressBar);
sFrame.setSize(200,200);
sFrame.setVisible(true);
}
/**
* Create a new instance of StartupPanel
* @param gameModeFileLoader
* @param campaignFileLoader
*/
public StartupPanel(GameModeFileLoader gameModeFileLoader, CampaignFileLoader campaignFileLoader)
{
this.gameModeFileLoader = gameModeFileLoader;
this.campaignFileLoader = campaignFileLoader;
message = new JPanel();
message.setLayout(new UnstretchingGridLayout(0, 1));
message
.add(new JLabel("Welcome to the PCGen " + PCGenPropBundle.getProdVersionSeries() + " Data Converter..."));
message.add(new JLabel(" "));
message.add(new JLabel("Loading Game Modes and Campaign Information."));
message.add(new JLabel(" "));
progressBar = new JProgressBar(0, 3);
progressBar.setValue(0);
progressBar.setStringPainted(true);
message.add(progressBar);
message.add(new JLabel(" "));
}
private void initialize() {
this.setLayout(new GridLayout(2, 0, 0, 0)); // -Create a two column grid
progressBar = new JProgressBar(); // -Create, initialize and setup a progress bar
progressBar.setValue((100 / cardCount));
this.add(progressBar); // -Positions the progress bar into the top column
JPanel navBar = new JPanel(); // -Create a two row grid for navigation buttons
this.add(navBar);
navBar.setLayout(new GridLayout(0, 2, 0, 0));
btnBack =
new JButton(
Constant.messages.getString(
"exportreport.previous.back.label")); // -Create the back button and
// place it into the left row
btnBack.setEnabled(false);
navBar.add(btnBack);
btnNext =
new JButton(
Constant.messages.getString(
"exportreport.forward.next.label")); // -Create the next button and
// place it into the right row
navBar.add(btnNext);
}
private void createSkillBlock(SkillProperty skillProperty, JPanel parentPanel, int x, int y) {
String skillDescription = skillProperty.getName();
skillDescription = Character.toUpperCase(skillDescription.charAt(0)) + skillDescription.substring(1);
JLabel lblSkill = JLabelFactory.createJLabel(skillDescription);
lblSkill.setBounds(x, y, 110, 20);
lblSkill.setToolTipText(skillProperty.getLongDescription());
parentPanel.add(lblSkill);
JLabel lblSkillValue = JLabelFactory.createJLabel(playerCharacter.getProperty(skillProperty).toString());
lblSkillValue.setBounds(x + 115, y, 15, 20);
lblSkillValue.setToolTipText(skillProperty.getLongDescription());
parentPanel.add(lblSkillValue);
JProgressBar skillProgressBar = JProgressBarFactory.createHorizontalJProgressBar(0, 100, imageInfoReader);
skillProgressBar.setBounds(x + 130, y, 130, 20);
skillProgressBar.setToolTipText(skillProperty.getLongDescription());
skillProgressBar.setValue(playerCharacter.getProperty(skillProperty).getPercentageUntilNextLevelUp());
parentPanel.add(skillProgressBar);
}
private void setProgressValues (JProgressBar pb, JLabel lbl, double value, String msg)
{
if (!pb.isVisible())
return ;
int pbVal = Math.min((int) (value * 100), 100) ;
if (pb.isIndeterminate())
pb.setIndeterminate(false) ;
pb.setValue(pbVal);
lbl.setText((msg == null)?(""):(msg));
}
/**
* Constructor
*
* @param progressBar The progress bar this has to update
*/
public ProgressDialog(Window parent, String dialogTitle) {
super(parent, dialogTitle, ModalityType.APPLICATION_MODAL);
setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
setResizable(false);
bundle = java.util.ResourceBundle.getBundle("course_generator/Bundle");
Container paneGlobal = getContentPane();
paneGlobal.setLayout(new GridBagLayout());
// -- Progress bar
progressBar = new JProgressBar(0, 100);
progressBar.setValue(0);
progressBar.setStringPainted(true);
progressBar.setPreferredSize(new Dimension(500, 30));
Utils.addComponent(paneGlobal, progressBar, 0, 0, 1, 1, 0, 0, 10, 10, 10, 10,
GridBagConstraints.BASELINE_LEADING, GridBagConstraints.BOTH);
// -- Cancel button
buttonCancel = new JButton(bundle.getString("Global.btCancel.text"));
buttonCancel.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
if (progressDialogListener != null) {
progressDialogListener.progressDialogCancelled();
}
}
});
Utils.addComponent(paneGlobal, buttonCancel, 0, 1, 1, 1, 0, 0, 0, 10, 10, 10, GridBagConstraints.CENTER,
GridBagConstraints.NONE);
pack();
// -- Center the dialog on the parent
setLocationRelativeTo(parent);
}
public TimerFrame() {
setUndecorated(true);
getContentPane().setBackground(Color.lightGray);
setShape(new RoundRectangle2D.Double(0, -20, GlobalSettings.WIDTH/2, 44, 20, 20));
setSize(GlobalSettings.WIDTH/2, 24);
setLocation(getX(), 0);
horizontalPositioner.tick();
setAlwaysOnTop(true);
setFocusable(false);
setType(Type.UTILITY);
setFocusableWindowState(false);
getContentPane().setLayout(new BorderLayout());
progressBar = new JProgressBar();
progressBar.setForeground(Color.lightGray);
progressBar.setBackground(Color.GREEN);
progressBar.setString("1 min");
progressBar.setStringPainted(true);
progressBar.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
progressBar.setBorderPainted(false);
progressBar.setValue(50);
progressBar.setFont(new Font("Consolas", Font.BOLD, 19));
progressBar.addMouseListener(new ProgressMouseListener());
progressBar.setCursor(new Cursor(Cursor.HAND_CURSOR));
getContentPane().add(progressBar);
}
public ExecutorProgressGui( int max ) {
frame = new JFrame();
JLabel label = new JLabel("Loading...");
JProgressBar jpb = new JProgressBar(0, max);
jpb.setIndeterminate(false);
JPanel panel = new JPanel(new BorderLayout(10, 10));
panel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
panel.add(label, BorderLayout.NORTH);
panel.add(jpb, BorderLayout.CENTER);
frame.add(panel);
frame.pack();
frame.setSize(w, h);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
frame.setIconImage(ImageCache.getBuffered(ImageCache.HORTONMACHINE_FRAME_ICON));
frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
progress = new IProgressPrinter(){
@Override
public void publish( ProgressUpdate update ) {
if (update.errorMessage != null) {
frame.dispose();
GuiUtilities.showErrorMessage(panel, update.errorMessage);
} else {
label.setText(update.updateString);
jpb.setValue(update.workDone);
}
}
@Override
public void done() {
if (frame != null && frame.isVisible())
frame.dispose();
}
};
}
/**
* Create the dialog to show the progress
*/
private void createProgressDialog()
{
_progressDialog = new JDialog(_parentFrame, I18nManager.getText(_dialogTitleKey));
_progressDialog.setLocationRelativeTo(_parentFrame);
_progressBar = new JProgressBar(0, 100);
_progressBar.setValue(0);
_progressBar.setStringPainted(true);
_progressBar.setString("");
JPanel panel = new JPanel();
panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
panel.setBorder(BorderFactory.createEmptyBorder(6, 6, 6, 6));
panel.add(new JLabel(I18nManager.getText(_labelKey)));
panel.add(_progressBar);
panel.add(Box.createVerticalStrut(6)); // spacer
JButton cancelButton = new JButton(I18nManager.getText("button.cancel"));
cancelButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
_function.cancel();
}
});
panel.add(cancelButton);
_progressDialog.getContentPane().add(panel);
_progressDialog.pack();
_progressDialog.setVisible(true);
}
private void addProgessBar() {
// Add progress bar
progressBar = new JProgressBar();
progressBar.setValue(25);
progressBar.setStringPainted(true);
Border border =
BorderFactory.createTitledBorder("Processing... <Press \"ESC\" to cancel> ");
progressBar.setBorder(border);
this.dialog.add(progressBar, BorderLayout.NORTH);
// this.dialog.repaint();
progressBar.setVisible(true);
this.dialog.pack();
}
private final void start (JProgressBar progressBar, JLabel progressLabel)
{
progressBar.setValue(0);
progressLabel.setText("Processing");
progressBar.setIndeterminate(true) ;
}
private final void done (JProgressBar progressBar, JLabel progressLabel)
{
progressBar.setValue(100);
}
public static void downloadFully(URL url, File target, JProgressBar progressBar) throws IOException {
// We don't use the settings here explicitly, since HttpRequests picks up the network settings from studio directly.
try {
URLConnection connection = url.openConnection();
if (connection instanceof HttpsURLConnection) {
((HttpsURLConnection) connection).setInstanceFollowRedirects(true);
((HttpsURLConnection) connection).setRequestProperty("User-Agent", "Mozilla/5.0 (Macintosh; U; PPC; en-US; rv:1.3.1)");
((HttpsURLConnection) connection).setRequestProperty("Accept-Charset", "UTF-8");
((HttpsURLConnection) connection).setDoOutput(true);
((HttpsURLConnection) connection).setDoInput(true);
}
connection.setConnectTimeout(3000);
connection.connect();
int contentLength = connection.getContentLength();
if (contentLength < 1) {
throw new FileNotFoundException();
}
if (progressBar != null) {
progressBar.setMinimum(0);
progressBar.setMaximum(contentLength);
}
OutputStream dest = new FileOutputStream(target);
InputStream in = connection.getInputStream();
int count;
int done = 0;
byte data[] = new byte[BUFFER_SIZE];
while ((count = in.read(data, 0, BUFFER_SIZE)) != -1) {
done += count;
if (progressBar != null) {
progressBar.setValue(done);
}
dest.write(data, 0, count);
}
dest.close();
in.close();
} finally {
if (target.length() == 0) {
try {
target.delete();
} catch (Exception e) {
}
}
}
}
private void updateProgress(final ProgressType progressType, final int value, final int max) {
final String sizeText = getSizeText(value);
this.transferSizeField.setValue(sizeText);
final long newTimestamp = System.currentTimeMillis();
final double lastTransferRate = this.lastTransferRate;
final long lastProgressValue = this.lastProgressValue;
final long lastTimestamp = this.lastTimestamp;
final long elapsed = newTimestamp - lastTimestamp;
double newTransferRate = Double.NaN;
if (elapsed > 0) {
newTransferRate = (value - lastProgressValue) / elapsed;
if (!Double.isNaN(lastTransferRate)) {
// Weighed average
newTransferRate = (newTransferRate + (lastTransferRate * 5.0)) / 6.0;
}
}
if (!Double.isNaN(newTransferRate)) {
this.transferRateField.setValue(round1(newTransferRate) + " Kb/sec");
final int cl = this.knownContentLength;
if ((cl > 0) && (newTransferRate > 0)) {
this.timeLeftField.setValue(Timing.getElapsedText((long) ((cl - value) / newTransferRate)));
}
}
this.lastTimestamp = newTimestamp;
this.lastProgressValue = value;
this.lastTransferRate = newTransferRate;
final JProgressBar pb = this.progressBar;
if (progressType == ProgressType.CONNECTING) {
pb.setIndeterminate(true);
pb.setStringPainted(true);
pb.setString("Connecting...");
this.setTitle(this.destinationField.getValue() + ": Connecting...");
} else if (max <= 0) {
pb.setIndeterminate(true);
pb.setStringPainted(false);
this.setTitle(sizeText + " " + this.destinationField.getValue());
} else {
final int percent = (value * 100) / max;
pb.setIndeterminate(false);
pb.setStringPainted(true);
pb.setMaximum(max);
pb.setValue(value);
final String percentText = percent + "%";
pb.setString(percentText);
this.setTitle(percentText + " " + this.destinationField.getValue());
}
}
private void initializeComponents() {
JPanel contentPane = (JPanel) this.getContentPane();
contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.PAGE_AXIS));
contentPane.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
if (fromVersion == null) {
contentPane.add(new JLabel("Please wait while " + ClientGameConfiguration.get("GAME_NAME") + " is downloaded..."));
} else {
contentPane.add(new JLabel("Downloading updates..."));
}
contentPane.add(Box.createVerticalStrut(5));
progressBar = new JProgressBar(0, max);
progressBar.setStringPainted(false);
progressBar.setValue(0);
contentPane.add(progressBar);
contentPane.add(Box.createVerticalStrut(5));
if (urlBase != null) {
// Set up page display.
browser = new JEditorPane();
browser.setContentType("text/html");
browser.setEditable(false);
Dimension dim = new Dimension(600, 440);
browser.setPreferredSize(dim);
browser.addPropertyChangeListener("page", new UpdateProgressBarMetaRefreshSupport());
browser.addHyperlinkListener(new UpdateProgressBarHyperLinkListener());
Dimension windowSize = new Dimension(640, 480);
setPreferredSize(windowSize);
// TODO: load page async?
try {
browser.setPage(urlBase + fromVersion + "/" + toVersion + ".html");
} catch (IOException e) {
System.out.println(e);
}
// Gige the page scroll bars if it needs them
final JScrollPane scrollPane = new JScrollPane(browser);
contentPane.add(scrollPane);
}
}