COMPGROUPS.NET | Search | Post Question | Groups | Stream | About | Register

### Problem updating a label

• Email
• Follow

I'm using a JLabel to indicate the status of a program I'm running in
another thread. The problem is that I want to do a "label.setText" to
"Please wait", let the other thread run (the call waits until it
returns), then use "label.setText" to display the result. The problem
is the "Please wait" is never seen. The result is displayed but no
matter what I do the label stays in it's initial state, telling the
user to "Press the run button", until the called program completes and
then the results are displayed. No "Please wait" in between. It's
making me nuts!! What the heck is going on!

The code is below:

There are a set of selection buttons that initially set label l3 as
in:

l3.setText ("Press Run Check to continue");

Then the run button trys to set it to Please Wait util the results
are displayed:

JButton b4 = new JButton ("Run Check");
b4.setBounds(60, 225, BTN_WD, BTN_HT);
{
public void actionPerformed(ActionEvent e)
{
strResult[0] = "10";

strResult = Utils.execCmdAndWait(command,true);

log.info ( "Integrit returned result: " + strResult[0]
);

if ( result.equals("1") )
{
l3.setText ( "RESULT: Possible file corruption!" );
}
else
{
l3.setText ( "RESULT: Files verified good!" );
}

}
});

Only the initial state and RESULT is displayed. The call to CmdAndWait
can take several minutes. During that time the label stays in it's
initial state until the call returns when the label changes to the
RESULT: text.

Any help here greatly appreciated. I think it's a swing update thing
but calling repaint() doesn't help either. AHHHHHHHHHHHHHHHHHHH!!


 0
Reply jkimble (60) 1/13/2006 1:43:13 PM

See related articles to this posting

James Kimble wrote:
> Only the initial state and RESULT is displayed. The call to CmdAndWait
> can take several minutes. During that time the label stays in it's
> initial state until the call returns when the label changes to the
> RESULT: text.

Sound's like a classic: You are blocking the event dispatching thread.
See the Top 5 list in the comp.lang.java.gui FAQ.

> Any help here greatly appreciated. I think it's a swing update thing
> but calling repaint() doesn't help either. AHHHHHHHHHHHHHHHHHHH!!

I think it's non compliance to the rules set by the Swing architecture.

/Thomas
--
The comp.lang.java.gui FAQ:
http://www.uni-giessen.de/faq/archiv/computer-lang.java.gui.faq/

 0
Reply nobody89 (1643) 1/13/2006 2:12:35 PM

This is a simple threading problem.  You're doing all your work in the
get updated till after you're done with the operation.

You need to do something like this:

class MyClass {
ActionListener l = new ActionListener() {
public void actionPerformed(ActionEvent e) {
public void run() {
doIt();
}
}.start();
}
};

private void doIt() {
strResult[0] = "10";
strResult = Utils.execCmdAndWait(command,true);
log.info ( "Integrit returned result: " + strResult[0]);

final String msg;
if ( result.equals("1") ) {
msg = "RESULT: Possible file corruption!";
} else {
msg = "RESULT: Files verified good!";
}
SwingUtilities.invokeLater(new Runnable() {
public void run() {
l3.setText(msg);
}
});
}
}

Hope this helps,

Walter Gildersleeve
Freiburg, Germany

______________________________________________________
URL Shortening
Free and easy, small and green.


 0
Reply funny_leech (17) 1/13/2006 2:15:52 PM

Thanks very much! I'm sure that'll fix it.


 0
Reply jkimble (60) 1/13/2006 3:13:32 PM

I implemented your solution (yes I copied it!!!) and it works great.
Thanks again!


 0
Reply jkimble (60) 1/13/2006 6:16:24 PM

On 13 Jan 2006 05:43:13 -0800, "James Kimble" <jkimble@one.net> wrote,
quoted or indirectly quoted someone who said :

>Please wait" is never seen. The result is displayed but no
>matter what I do the label stays in it's initial state, telling the
>user to "Press the run button", until the called program completes and
>then the results are displayed. No "Please wait" in between. It's
>making me nuts!! What the heck is going on!

You are tying up the Swing thread. You never let it have a chance to
--
http://mindprod.com Java custom programming, consulting and coaching.

 0

5 Replies
47 Views

Similar Articles

12/12/2013 2:28:16 PM
[PageSpeed]

Similar Artilces:

Problems with update
I have just bought and installes CS2. Everytime the program is started it says that it was not able to update and that I need to reinstall the allipcation. I have reinstalled once, but still same error messege. What to do? Anybody else tried this? Does your existing hardware meet the minimum photoshop requirements? -- Don Leman <aerangis@gmail.com> wrote in message news:1166283927.647973.133330@n67g2000cwd.googlegroups.com... >I have just bought and installes CS2. Everytime the program is started > it says that it was not able to update and that I need to reinstall the >...

Truncated Label Problem
Hi All, I have a dialog with a panel in its lower section that uses FlowLayout and in which I display messages using JLabel to the user. However if the second message I display is longer than the very first message then it and all the subsequent messages are truncated to that original label's length. I have tried everything to fix it, what am I doing wrong? Thanks, Fred. On 27 Jun 2005 00:55:33 -0700, MrFredBloggs@hotmail.com wrote: > I have tried everything to fix it, .. Everything short of including an SSCCE. -- Andrew Thompson http://www.PhySci.org/codes/ Web & IT Help...

GUI Updation Problem
A simple chatting system i am dealing with is as follows: The Client accepts text in a TextField and sends it to a server. Server sends it to all the connected clients. The message received by Client is appended to a JTextPane. This works fine I have written one special client in which using the 'Robot' class of AWT, It automatically enters the text 'TESTING' in the TextField and let it press the Enter key. The Testing method is set to run in an indefinite loop so that this Client will send this message continuosly after some delay. This mechanism also works.... but the probl...

Strange Update Problem
Hi, I have following problem. In a piece of VBA code in the onclick event of a delete button I delete a specific entry in a table called (TBL_Tasks) via the DoCmd.RunSQL command. Directly after that I start a subroutine. In this subroutine I go check in TBL_Tasks to see how many records I still have, but, unforunately the record seems to be not yet deleted. I placed a Me.Requery between de delete and the start of the subroutine, but it doesn't seem to help. Afterwards, after the subroutine ends, I go chek in the table and the record seems to be deleted. (imagine I have 21 tasks in TBL...

Problem with update query
I am trying to run an update query and am having problems with null values. Starting from the beginning - I created a new table from my original table, selecting distinct combinations of these rows: Family, Genus, Species, Variety, Author I then added an ID field to uniquely identify each of these rows. Sample of data that may be in these rows: taxa_id: 1 Family: Aceraceae Genus: Acer Species: circinatum Variety: (is null) Author: (is null) The records vary as to how much information is in them. They may have all of these fields, or only Family and Genus. Now I would like to go back...

Update problem with Novell
Hi, C55H, ABC A window with two browse list boxes which both use temp files. Temp files are created from tps files located on a Novell server. Selection on browse 1 recreates the temp file of browse 2 and updates browse 2. This has worked absolutely fine except on Novell based network: browse 2 does not update immediately, user has to click browse 1 a couple of times until it happens. In addition get commands seem to fail occasionally (with errorcode 35 I guess). I know that write cache enabled on Novell client software might cause some problems but this shouldn't be the case this tim...

updating PHP problem
I've installed PHP 4.3.6 on my laptop. My dev machine is on PHP 4.3.3 Since, some lines doesn't work anymore: 2: header("Cache-Control: max-age=" . $this->allowcache_expire * 60); gives me those errors: Notice: Undefined variable: this in c:\inetpub\wwwroot\Connections\config.php on line 2 Warning: Cannot modify header information - headers already sent by (output started at c:\inetpub\wwwroot\Connections\config.php:8) in c:\inetpub\wwwroot\Connections\config.php on line 2 Warning: session_start(): Cannot send session cookie - headers already sent by (output started a... CVS update problem The last 2 weeks i have problem to update from Sourceforge using Tortoise CVS. I don't now if the problem is due to restrictions in my network infrastructure or i'm using wrong parameters. In C:\xHarbour: "C:\Program Files\TortoiseCVS\cvs.exe" -z9 update -d -P CVSROOT=:pserver:anonymous@xharbour.cvs.sourceforge.net:/cvsroot/xharbour connect to xharbour.cvs.sourceforge.net:2401 failed: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. Error, ... DataSet Update Problem I know this is very very silly. But I am stuck and don't know what to do. I have a simple form which has 1 textbox and a 'Save' button. I have created a Database connection and an Adapter with Dataset with the help of Wizards. I have binded by text box control to one of the database field. When the form gets loaded it displays the field information correctly. "Me.SqlDataAdapter1.Fill(DsBasicData1)" However, when I press the save button it does not update the database behind it. I have given the following code to the click event of save button. "Me.SqlDat... Problem with Update statement When I run the following update statement, the Bulkline field gets truncated on any record with the corresponding gift field. Ex: Bulkine before running statement: CA13 bulkline after running statement: CA1 Update Orders Set OOS = 'Y' Where Gift = '4200' and BulkLine LIKE 'C%' The OOS field gets updated correctly, but all records with Gift = 4200 have the bulkline record truncated, even the records that don't satisfy the LIKE 'C%' Any ideas as to why this is happening? Shane -- How's things going! It is possible (and even likely) that your D... tar update problem I'm having a problem with 'tar update' option. Tar keeps updating the archive, appending a file at the end, although nothing has changed in given directories. I'm archiving into a file, not a tape. Here is an example: # pwd / # tar cf x.tar etc/opt # tar uvf x.tar etc/opt/OV/share/backgrounds/africa.gif a etc/opt/OV/share/backgrounds/africa.gif 49K # tar uvf x.tar etc/opt/OV/share/backgrounds/africa.gif a etc/opt/OV/share/backgrounds/africa.gif 49K # tar uvf x.tar etc/opt/OV/share/backgrounds/africa.gif a etc/opt/OV/share/backgrounds/africa.gif 49K # tar tvf x.tar |grep africa... Update on the WPA problems I posted a message describing how I could not get a plain vanilla case of WPA to work with my Atheros based laptop. (WEP worked fine). My plan, as of right now, is as follows: 1) Install the latest madwifi drivers from MadWifi SVN 2) Install the latest wpa_supplicant from dev version 3) Try NetworkManagerDispatcher as suggested by Scott. I can only try this when I get home in the evening. I already compiled and installed madwifi and wpa_supplicant. My opinion is crystallizing that the root of the issue is wpa_supplicant, not properly getting authorization. i ... Ipod updating problems I'm trying to sort out a mate who is having problems updating the songs on her Ipod. For some reason I can't fathom she's getting the following error message: The Ipod "Pookie's iPod" (don't laugh I didn't name it) cannot be updated because there is not enough free space to hold all of the songs in the iTunes music Library. Would you like iTunes to choose a selection of songs to copy to this iPod? But as nearly as I can tell the iPod has 2.7 gigs free and that the total available memory is greater than what is selected in the Library. Any tips? jollyspa... Rom update problems Heya! Just got my 49G+ today and now I am trying to install the newest ROM 1.22 on it. I got the ROM with a CD from the salesperson, and I tried installing it, following the instructions HP provides ( http://h20015.www2.hp.com/en/softwareDownloadIndex.jhtml?reg=&cc=ch&softitem=ca-14639-2&prodId=hp49ggraph351775&lc=en&sw_lang=en&pagetype=software ) .. I can connect to the calculator perfectly fine, but I cannot access the "ROM" menu as said at point 3 in the "how to". It is unaccessible, regardless what I tried. Everything else works fine. What am I ... Update Problem #2 Hi I have this query to update some records in my table. It is working good but my problem is this query very slow. Is any way to do this job faster. UPDATE SWKPIFA Y SET Y.SWKPIFA_TRAN_CODE = 'G' WHERE SWKPIFA_START_TERM = ( SELECT MIN(X.SWKPIFA_START_TERM) FROM SWKPIFA X WHERE Y.SWKPIFA_PIDM = x.SWKPIFA_PIDM AND Y.SWKPIFA_MAJR_CODE = X.SWKPIFA_MAJR_CODE) AND SWKPIFA_END_TERM = ( SELECT MAX(X.SWKPIFA_END_TERM) FROM SWKPIFA X WHERE Y.SWKPIFA_PIDM = x.SWKPIFA_PIDM AND Y.SWKPIFA_MAJR_CODE = X.SWKPIFA_MAJR_C... problem with \label \ref Hello, I have a problem with referring to figures when using \label and \ref. I'm using the \documentclass{book}. If I'm referring to a figure in a chapter, e.g. \begin{figure} \begin{center} \includegraphics[width=120mm]{figuren/chapter2/formationbandstructure} \caption{Formation of a band structure.} \end{center} \label{fig:formationbandstructure} \end{figure} with \ref{fig:formationbandstructure}, I never get the right reference number. The figure has got as a \caption Figure 1.1, but in my text I'm getting only a `1� as a reference to this figure. If I'm making a \se... QUERY AND UPDATE PROBLEM Having a problem updating my database from a web page, through a submission form. Can anyone help? ----THIS IS MY CODE IN update.php----(user, pass, and database are typed in directly, I changed them here for securiy reasons :) ) <?php /*---CONNECT TO DATABASE---*/$conn = mysql_connect("localhost", "user", "pass") or die(mysql_error()); mysql_select_db("database",$conn) or die(mysql_error());$event = $_GET["id"];$title=$_POST['title'];$date=$_POST['datetime'];$desc=\$_POST['desc']; //---UPDATE ENTRY IN DA...

Updating of a Tree when the label changes
I have seen postings about similar problems, and have tried duplicating what others have tried, but my tree never updates with the new values. In the code below, I have stepped through and see the new nodes with the correct values, but it never redraws. The reason that I am removing and reinserting the node is that just calling node.setUserObject(newVal) does not change the length of the label. Atleast it updates the label to ... :) Here is the code snipet. If I don't actually expand the tree until later in the game, I do get the current value for SysUpTime and numPktsRecvd, but it ne...

Old JTree Update Problem
Hi all out there I want to come back to this dammed old JTree problem which doesn't seem to be solved correctly. Look at the code at the end, run it an press the switch button. What you see is that the long text gets abbreviated with an ellipse (...). The usual solutions hack around by setting the initial text to the longest one which will ever be displayed. That's not the kind of solution I try to find. The usual advises are to use validate(), which - together with invalidate and revalidate - do not solve the problem. I've read in one post that the bounds of the nodes are cached...

Problem updating PHP Include?
Hello Everyone, I have two Include PHP scripts running in two scroll boxes on a test page at http://www.usernomics.com/ergonomic-products-data2.html . The PHP script is being pulled in from FeedDigest.com. I already have a similar thing running on my site but it is from RSSFeedBurner.com and it works fine. I am trying to change over because the original one would not validate in Strict 4.01 but this new one does validate and it has no advertising. The only problem is that it is not updating itself. It does update when I log into FeedDigest and manually reload it. My htaccess file has: ...