Results 1 to 8 of 8
Thread: JprogressBar
- 03-23-2010, 04:18 PM #1
Member
- Join Date
- Mar 2010
- Posts
- 43
- Rep Power
- 0
-
- 03-24-2010, 03:05 AM #3
Senior Member
- Join Date
- Dec 2008
- Posts
- 526
- Rep Power
- 0
wait a minute...
Is your progress bar filled up?
What you mean saying "cannot see any results"?
- 03-24-2010, 09:05 AM #4
Member
- Join Date
- Mar 2010
- Posts
- 43
- Rep Power
- 0
No, the progress bar stays there, without any visual results of any type
Here is the code, the line I am referring is in the method goButtonActionPerformed
Java Code:package progressbartest; import org.jdesktop.application.ResourceMap; import org.jdesktop.application.SingleFrameApplication; import org.jdesktop.application.FrameView; import org.jdesktop.application.TaskMonitor; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.Timer; import javax.swing.Icon; /** * The application's main frame. */ public class ProgressBarTestView extends FrameView { public ProgressBarTestView(SingleFrameApplication app) { super(app); initComponents(); // status bar initialization - message timeout, idle icon and busy animation, etc ResourceMap resourceMap = getResourceMap(); int messageTimeout = resourceMap.getInteger("StatusBar.messageTimeout"); messageTimer = new Timer(messageTimeout, new ActionListener() { public void actionPerformed(ActionEvent e) { statusMessageLabel.setText(""); } }); messageTimer.setRepeats(false); int busyAnimationRate = resourceMap.getInteger("StatusBar.busyAnimationRate"); for (int i = 0; i < busyIcons.length; i++) { busyIcons[i] = resourceMap.getIcon("StatusBar.busyIcons[" + i + "]"); } busyIconTimer = new Timer(busyAnimationRate, new ActionListener() { public void actionPerformed(ActionEvent e) { busyIconIndex = (busyIconIndex + 1) % busyIcons.length; statusAnimationLabel.setIcon(busyIcons[busyIconIndex]); } }); idleIcon = resourceMap.getIcon("StatusBar.idleIcon"); statusAnimationLabel.setIcon(idleIcon); progressBar.setVisible(false); // connecting action tasks to status bar via TaskMonitor TaskMonitor taskMonitor = new TaskMonitor(getApplication().getContext()); taskMonitor.addPropertyChangeListener(new java.beans.PropertyChangeListener() { public void propertyChange(java.beans.PropertyChangeEvent evt) { String propertyName = evt.getPropertyName(); if ("started".equals(propertyName)) { if (!busyIconTimer.isRunning()) { statusAnimationLabel.setIcon(busyIcons[0]); busyIconIndex = 0; busyIconTimer.start(); } progressBar.setVisible(true); progressBar.setIndeterminate(true); } else if ("done".equals(propertyName)) { busyIconTimer.stop(); statusAnimationLabel.setIcon(idleIcon); progressBar.setVisible(false); progressBar.setValue(0); } else if ("message".equals(propertyName)) { String text = (String)(evt.getNewValue()); statusMessageLabel.setText((text == null) ? "" : text); messageTimer.restart(); } else if ("progress".equals(propertyName)) { int value = (Integer)(evt.getNewValue()); progressBar.setVisible(true); progressBar.setIndeterminate(false); progressBar.setValue(value); } } }); } /** This method is called from within the constructor to * initialize the form. * WARNING: Do NOT modify this code. The content of this method is * always regenerated by the Form Editor. */ @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code"> private void initComponents() { mainPanel = new javax.swing.JPanel(); goButton = new javax.swing.JButton(); statusPanel = new javax.swing.JPanel(); javax.swing.JSeparator statusPanelSeparator = new javax.swing.JSeparator(); statusMessageLabel = new javax.swing.JLabel(); statusAnimationLabel = new javax.swing.JLabel(); progressBar = new javax.swing.JProgressBar(); mainPanel.setName("mainPanel"); // NOI18N org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(progressbartest.ProgressBarTestApp.class).getContext().getResourceMap(ProgressBarTestView.class); goButton.setText(resourceMap.getString("goButton.text")); // NOI18N goButton.setName("goButton"); // NOI18N goButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { goButtonActionPerformed(evt); } }); javax.swing.GroupLayout mainPanelLayout = new javax.swing.GroupLayout(mainPanel); mainPanel.setLayout(mainPanelLayout); mainPanelLayout.setHorizontalGroup( mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(mainPanelLayout.createSequentialGroup() .addGap(178, 178, 178) .addComponent(goButton) .addContainerGap(192, Short.MAX_VALUE)) ); mainPanelLayout.setVerticalGroup( mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, mainPanelLayout.createSequentialGroup() .addContainerGap(124, Short.MAX_VALUE) .addComponent(goButton) .addGap(120, 120, 120)) ); statusPanel.setName("statusPanel"); // NOI18N statusPanelSeparator.setName("statusPanelSeparator"); // NOI18N statusMessageLabel.setName("statusMessageLabel"); // NOI18N statusAnimationLabel.setHorizontalAlignment(javax.swing.SwingConstants.LEFT); statusAnimationLabel.setName("statusAnimationLabel"); // NOI18N progressBar.setName("progressBar"); // NOI18N javax.swing.GroupLayout statusPanelLayout = new javax.swing.GroupLayout(statusPanel); statusPanel.setLayout(statusPanelLayout); statusPanelLayout.setHorizontalGroup( statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(statusPanelSeparator, javax.swing.GroupLayout.DEFAULT_SIZE, 400, Short.MAX_VALUE) .addGroup(statusPanelLayout.createSequentialGroup() .addContainerGap() .addComponent(statusMessageLabel) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 214, Short.MAX_VALUE) .addComponent(progressBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(statusAnimationLabel) .addContainerGap()) ); statusPanelLayout.setVerticalGroup( statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(statusPanelLayout.createSequentialGroup() .addComponent(statusPanelSeparator, javax.swing.GroupLayout.PREFERRED_SIZE, 2, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addGroup(statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(statusMessageLabel) .addComponent(statusAnimationLabel) .addComponent(progressBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(3, 3, 3)) ); setComponent(mainPanel); setStatusBar(statusPanel); }// </editor-fold> private void goButtonActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: progressBar.setValue(100); } // Variables declaration - do not modify private javax.swing.JButton goButton; private javax.swing.JPanel mainPanel; private javax.swing.JProgressBar progressBar; private javax.swing.JLabel statusAnimationLabel; private javax.swing.JLabel statusMessageLabel; private javax.swing.JPanel statusPanel; // End of variables declaration private final Timer messageTimer; private final Timer busyIconTimer; private final Icon idleIcon; private final Icon[] busyIcons = new Icon[15]; private int busyIconIndex = 0; }Last edited by cotarelo; 03-24-2010 at 09:07 AM.
- 03-24-2010, 12:47 PM #5
Uncompilable IDE generated code neither helps you to learn Swing nor is conducive to getting help on a forum. Recommended reading (in no particular order)
SSCCE : Java Glossary
How To Ask Questions The Smart Way
Trail: Creating a GUI With JFC/Swing (The Java™ Tutorials)
In that monstrosity of code, you seem to have a couple of Timers. One of them is probably resetting any progress balue you set elsewhere.
db
- 03-24-2010, 07:45 PM #6
Senior Member
- Join Date
- Dec 2008
- Posts
- 526
- Rep Power
- 0
No, the code like a
wouldn't work because you have to useJava Code:private void goButtonActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: progressBar.setValue(100); }
a) DefaultBoundedRangeModel(from,0,0,to)
b) put the progress bar filling in sep. thread. public void run(){} method
c) controll it's processing with a loop like a while()
- 03-25-2010, 11:28 AM #7
Member
- Join Date
- Mar 2010
- Posts
- 43
- Rep Power
- 0
Thanks for the reply! I am still trying but I get no results.
I declared in the class
then on the initcomponentsJava Code:DefaultBoundedRangeModel model = new DefaultBoundedRangeModel(0, 0, 0, 100);
and then inside the goButtonActionPerformed methodJava Code:progressBar = new javax.swing.JProgressBar(model);
It compiles without errors but it does not show progress bar.Java Code:new Thread() { public void run() { int value = progressBar.getValue() + 7; if (value > progressBar.getMaximum()) { value = progressBar.getMaximum(); } progressBar.setValue(value); } }.start();
Could you give me an example?
Thanks!
- 03-26-2010, 03:13 AM #8
Senior Member
- Join Date
- Dec 2008
- Posts
- 526
- Rep Power
- 0
Similar Threads
-
JProgressBar inside a JDialog
By Mikey_S in forum AWT / SwingReplies: 10Last Post: 07-13-2009, 02:55 PM -
Updating a JProgressBar from another thread?
By Xiphias in forum AWT / SwingReplies: 3Last Post: 03-18-2009, 01:48 AM -
Placing a JProgressBar over my JPEG image
By hitmen in forum AWT / SwingReplies: 7Last Post: 03-08-2009, 10:16 AM -
[SOLVED] Netbeans Desktop App & JProgressBar
By SebScoFr in forum NetBeansReplies: 3Last Post: 11-27-2008, 11:00 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks