Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!us.feeder.erje.net!feeder.erje.net!eu.feeder.erje.net!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Kevin Nathan Newsgroups: comp.lang.java.gui Subject: setText() is not always updating Jtextfield and Jlabel items Date: Thu, 26 Feb 2015 13:23:17 -0700 Lines: 101 Message-ID: <20150226132317.6bbbc29a@efreet.linux> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Trace: individual.net erygcjPR30WDNddML3ULHQvwmSzbAjnRInPlFV0jfoG5MeEdKG Cancel-Lock: sha1:uLDABqPRFDKk1wMkIVdV4lsjYsQ= X-Newsreader: Claws Mail 3.10.1 (GTK+ 2.24.18; i586-suse-linux-gnu) X-Face: %/gp4MCQT=`#JS##?-]V9ksid6OSR@(wbF"bK6wSLO$u,%(N@X~bVhAD+\A_[gRhx*T6=fq "N_5H8.v[&;q0iw!s_wuL05B0xg#OYUkbn#@&U_]fL%o==~2sphc?*L+bicO!POJLG#p'N.]J0/p_w Z^(.kOB%Ob914-V>?GI; Xref: csiph.com comp.lang.java.gui:5453 I could use some direction about where to look for this. I am still pretty new to Java. I have a user input screen with multiple JTextFields for user input and matching JLabels for informational output for users. This is for a livestock auction system. While the animals are moving around on the scale, the scale instrument (a serial port device) returns an indication of "motion" that we want to show to the user. When the motion goes away, the actual weight gets written to the Weight JTextField. However, during the motion (which can be anywhere from non-existent to many seconds) we want to write "Motion" in the textfield and the actual, changing, weights in the label field. This is what is not happening. After the motion stops, the true weight does get written correctly, using setText(). The serial port routine returns an error code of -2 if there is motion (and several other error codes that are handled correctly) and that is what I am using. Here are some code snippets to show what is being attempted, I hope it's enough to make sense: MainScreen class: ----------------- // Trying new "Motion" routine: while (clerkFuncs.scaleErr == -2) { weight = clerkFuncs.readScale(tr); showMotion(weight); } private void showMotion(long wt) { noteField[1][weightRow].setText(Long.toString(wt)); // noteField[1][weightRow].setText("Motion"); editField[1][weightRow].setText("Motion"); } ClerkFuncs class: ----------------- // weight and weightStr are global in ClerkFuncs. I don't like it // but that's how it was written. public long readScale(TransClass tr) { clearScaleReturns(); // clears weight string and error var if (!scale.scalePortErr) { getAutoWeight(); checkForWeightErrors(); } else { // manual weight entry getManualWeight(); } return (weight); } private void getAutoWeight() { scale.startScale(); do { weightStr = scale.getWeight(); } while (scale.getStatus() && weightStr.equals("")); scale.stopScale(); } private void checkForWeightErrors() { scaleErr = scale.scaleErr; try { String trimmed = weightStr.trim(); if (!trimmed.isEmpty()) { weight = Long.parseLong(trimmed); } else { weight = 0L; } } catch (NumberFormatException ex) { System.out.println("checkForWeightErrors Exception: " + ex); System.out.println("weightStr: [" + weightStr + "]"); scaleErr = -3; // bad scale return weight = 0L; } } I am completely puzzled why "setText" does not work in this instance, but works everywhere else I am using it. Thanks for any help, or pointers to pages that may help me to understand this -- Kevin Nathan (Arizona, USA) Linux is not a destination, it's a journey -- enjoy the trip! Linux 3.7.10-1.45-desktop 12:49pm up 7 days 3:18, 18 users, load average: 0.38, 0.46, 0.74