๐Ÿš€ go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.swing
Article #12105

Re: JProgressBar??? example!!!!!!!

#12105
From: Martin Schmitz
Date: Wed, 24 Feb 1999 00:00
104 lines
3169 bytes
and here's an example


import com.sun.java.swing.*;

class Progress extends JFrame
{
	JProgressBar m_bar = new JProgressBar();

	public static void main (String[] arg)
	{
		new Progress();
	}

	public Progress()
	{
		m_bar.setMinimum(0);
		m_bar.setMaximum(100);
		this.getContentPane().add(m_bar);
		pack();
		show();
		doWork();
	}


	private void doWork()
	{
		Thread t = new Thread()
		{
			public void run()
			{
				for(int i=0,j=0; i< 10000;i++,j++)
				{
					System.out.println(i +" loops durchlaufen");
					if(j == 100)
					{
						j = 0;
						m_bar.setValue(i / 100);
					}
					//this is needed on unix, because of the green thread
implementation
					//Thread.currentThread().yield();
				}
			}
		};
		t.start();
	}
}




Martin Schmitz wrote:
> 
> hi,
> 
> you should read the swing documentation carefully!!!!!!!!!
> 
> the progressbar can't be updated, because you're doing all the work
> inside the event-dispatching thread. that means the messages for
> repaint,validate a.s.o. don't get processed until your method finishes!
> the only save and clean solution is to use a thread to do all your
> processing (try the worker class available at java.sun.com) and call the
> progressbar.setValue method from this thread!
> martin
> 
> Dieter Mach wrote:
> >
> > Hi,
> >
> > we also had serious problems with updat๏ฟฝng a progress bar. We found this
> > working:
> >
> >   progressBar.paintImmediately(progressBar.getBounds());
> >
> > I don't know wether this will work in your app also, because from the code
> > snipplet I can't see how you add the progress bar to your dialog or panel. I
> > think it woud be a good idea not to create a new JProgressBar every time
> > before passing the setValue() method. Also, don't forget to call something
> > like
> >
> >   progressBar.setMinimum(0);
> >   progressBar.setMaximum(100);
> >
> > before using the progress bar.
> >
> > Dieter
> >
> > Marcel Hell schrieb in Nachricht <7asbfp$s6c8@forums.borland.com>...
> > >
> > >Vasudevan Srinivasan schrieb in Nachricht
> > <36D1B06A.32258010@netrisk.com>...
> > >>Hi,
> > >>Just a guess, try calling the jProgressBar1.repaint() or validate() or
> > >>similar-functioning methods immediately after jProgressBar1.setValue()
> > >>
> > >>Vasu
> > >>
> > >>
> > >
> > >I've also tried that, but nothing happens!
> > >I can't get it to be updated!!!!
> > >
> > >
Technical Details
Message-ID: <36D3C70E.ACF07A6D@teamworks.de>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <7asa65$s6f3@forums.borland.com> <36D1B06A.32258010@netrisk.com> <7asbfp$s6c8@forums.borland.com> <7atidp$1785@forums.borland.com> <36D28D4D.4F81E9D2@teamworks.de>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII
X-Google-Thread: 111d45,c7a418e2d93c1eb4
X-Google-Attributes: gid111d45,public
From: Martin Schmitz <mschmitz@teamworks.de>
Subject: Re: JProgressBar??? example!!!!!!!
Date: 1999/02/24
Message-ID: <36D3C70E.ACF07A6D@teamworks.de>
X-Deja-AN: 447829031
Content-Transfer-Encoding: 8bit
References: <7asa65$s6f3@forums.borland.com> <36D1B06A.32258010@netrisk.com> <7asbfp$s6c8@forums.borland.com> <7atidp$1785@forums.borland.com> <36D28D4D.4F81E9D2@teamworks.de>
X-Accept-Language: en
Content-Type: text/plain; charset=iso-8859-1
Organization: Another Netscape Collabra Server User
Mime-Version: 1.0
Newsgroups: borland.public.jbuilder.java.swing