NetBeans Forums

 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
  

Swing+How to use generated NetBeans ProgressBar code

 
Post new topic   Reply to topic    NetBeans Forums -> NetBeans Users
View previous topic :: View next topic  
Author Message
comm64



Joined: 12 Jan 2009
Posts: 1

PostPosted: Mon Jan 12, 2009 3:23 pm    Post subject: Swing+How to use generated NetBeans ProgressBar code Reply with quote

Hi, I need an example to use this code and display a progressBar:


Code:

public class DesktopApplication1View extends FrameView {

    public DesktopApplication1View(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);
                }
            }
        });
    }

    @Action
    public void showAboutBox() {
        if (aboutBox == null) {
            JFrame mainFrame = DesktopApplication1.getApplication().getMainFrame();
            aboutBox = new DesktopApplication1AboutBox(mainFrame);
            aboutBox.setLocationRelativeTo(mainFrame);
        }
        DesktopApplication1.getApplication().show(aboutBox);
    }




thanks
Back to top
Rocco



Joined: 08 Jan 2009
Posts: 17
Location: Orta di Atella (CE, Italy)

PostPosted: Tue Jan 13, 2009 2:00 pm    Post subject: Reply with quote

Try in this way:
create an Action, set the class that contains the method, set the method name; we'll call the action "myAction";
set the Background Task checkbox to TRUE;
set text string and tooltip string (optional);
you'll get this code:

@Action
public Task myAction() {
return new MyActionTask(org.jdesktop.application.Application.getInstance(desktopapplication1.DesktopApplication1.class));
}

private class MyActionTask extends org.jdesktop.application.Task<Object, Void> {
MyActionTask(org.jdesktop.application.Application app) {
// Runs on the EDT. Copy GUI state that
// doInBackground() depends on from parameters
// to MyActionTask fields, here.
super(app);
}
@Override protected Object doInBackground() {
// Your Task's code here. This method runs
// on a background thread, so don't reference
// the Swing GUI from here.
return null; // return your result
}
@Override protected void succeeded(Object result) {
// Runs on the EDT. Update the GUI based on
// the result computed by doInBackground().
}
}

Now, in the doInBackground() method, use the setProgress() method to manage your progress bar.

This task hould be easy, but if you face some trouble please post again.

Bye Bye.
Back to top
Rune Henning Johansen



Joined: 12 Mar 2009
Posts: 7

PostPosted: Thu Mar 12, 2009 1:51 pm    Post subject: Automatic start? Reply with quote

Thanks to Rocco for good advice!

But how can I get this started automatically when the program starts?
Back to top
rdblaha1
Posted via mailing list.





PostPosted: Thu Mar 12, 2009 8:27 pm    Post subject: Swing+How to use generated NetBeans ProgressBar code Reply with quote

Rune Henning Johansen wrote:
Quote:

But how can I get this started automatically when the program starts?



http://www.nabble.com/Need-a-Simple-Example-of-How-To-Use-NB-generated-TaskMonitor---Progress-Bar-cde.-td19220786.html#a19338802
Here's a link to my similar question between Task Monitor and Progress Bar.
Hopefully you can glean some usable information from the information I
received. Personally I haven't got what I need working yet, but as I say,
Maybe it will help you get started.

--
View this message in context: http://www.nabble.com/Swing%2BHow-to-use-generated-NetBeans-ProgressBar-code-tp22477516p22484730.html
Sent from the Netbeans IDE Users mailing list archive at Nabble.com.
Back to top
Rune Henning Johansen



Joined: 12 Mar 2009
Posts: 7

PostPosted: Wed Mar 18, 2009 7:19 pm    Post subject: Reply with quote

Thanks for the answer! But it wasn't that I was looking for. Sorry!

I need a sort of 'Set Action ...' for a frame the first time.

Here I have tried to to describe the problem with the code: http://moradi.no/count/
Back to top
Rocco



Joined: 08 Jan 2009
Posts: 17
Location: Orta di Atella (CE, Italy)

PostPosted: Wed Mar 25, 2009 11:04 am    Post subject: Reply with quote

I hope the demo herewith attached, supplied with source code as Netbeans 6.5 project, may help you.

I suggest you to go to menu Windows/Other/Application Actions, the select "startCount" action, then click on "View Source" button.

Notice that you can recall the method "startCount" from wherever you need inside the application, not only from a menu item.



CounterDemo.zip
 Description:

Download
 Filename:  CounterDemo.zip
 Filesize:  209.94 KB
 Downloaded:  2482 Time(s)

Back to top
Rune Henning Johansen



Joined: 12 Mar 2009
Posts: 7

PostPosted: Sun Mar 29, 2009 5:39 pm    Post subject: Reply with quote

Thanks for the demo! But I was not able to run startCount at the start and see the action.

(I also got a small error: http://moradi.no/count/code-02.html)


I have been able to make a program demonstrating what I want it to do: http://moradi.no/count/code-03.html

This is not the way it should be done, but it's the only way I'm able to do it!
Back to top
Rocco



Joined: 08 Jan 2009
Posts: 17
Location: Orta di Atella (CE, Italy)

PostPosted: Mon Mar 30, 2009 6:47 am    Post subject: Reply with quote

try to modify your code as follows (in bold):

public SimpleCountView ( SingleFrameApplication app )
{
super ( app );
initComponents ();
/*
* Do a counting when the program starts.
*/
doCount (); //this doesn't work
new CountThread(); //this should work

}
Back to top
Rune Henning Johansen



Joined: 12 Mar 2009
Posts: 7

PostPosted: Mon Mar 30, 2009 1:03 pm    Post subject: Reply with quote

Now I am a little confused.

A call on doCount (); does work in my program. The routine simply disables a menu, changes the status and makes a call on new CountThread().

So why it doesn't work with you, I simply don't understand. And I can't see why your suggestion would help. Sorry!

But I am most interested in how to modify your code so the program starts a counting at the start.
Back to top
Rocco



Joined: 08 Jan 2009
Posts: 17
Location: Orta di Atella (CE, Italy)

PostPosted: Tue Mar 31, 2009 8:48 pm    Post subject: Reply with quote

You can modify my code adding:
new StartCountTask(getApplication()).execute();

or, if you prefer, use this:
jMenuItem1.doClick(); that performs the same task.
Back to top
Rune Henning Johansen



Joined: 12 Mar 2009
Posts: 7

PostPosted: Wed Apr 01, 2009 6:23 am    Post subject: Reply with quote

Your first suggestion worked, but without the progressbar running.

The second suggestion worked perfect!

Problem solved!

Thanks!

PS: All the relevant code for my solution - http://moradi.no/count/code-04.html
Back to top
daisywhite333



Joined: 20 Mar 2012
Posts: 5

PostPosted: Tue Mar 20, 2012 7:51 am    Post subject: re Reply with quote

Sorry about that ,maybe ,a Barcode Add-In for Microsoft Excel Generation Guide can be helped ,not sure weather it helped@@http://www.keepautomation.com/guide/excel_barcode_addin.html
Back to top
Display posts from previous:   
Post new topic   Reply to topic    NetBeans Forums -> NetBeans Users All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Powered by phpBB
By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo