473,769 Members | 2,246 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Really ignorant TextField (AWT) question from an idiot.


Help me, I'm suffering!

Situation: I have a load() function which loads a bunch
of TextFields with values. There are TextListeners
registered for each of these TextFields. Thus, changing the
text in any of them fires off a TextEvent, even if done
programmaticall y (by means of setText()).

The problem: I need all the various TextEvents fired off
during the load operation (as a result of using TextField.setTe xt())
to be handled BEFORE the load() function completes. In other words,
load() must hang around waiting for all these events to have been
handled by somehow blocking on a state variable.

Some code:

public class Stupid extends Something implements TextListener
{
TextField lname = new TextField();
TextField fname = new TextField();

public Stupid()
{
lname.setName(" LNAME");
fname.setName(" FNAME");

lname.addTextLi stener(this);
fname.addTextLi stener(this);

load();
}

public void textValueChange d(TextEvent e)
{
System.out.prin tln(paramString () + ": " + e.getSource().t oString());
}

public void load()
{
System.out.prin tln("LOADING... ");

lname.setText(" Quixote");
fname.setText(" Don");

System.out.prin tln("LOADED.");
}
}

Some output:

LOADING...
LOADED.
TEXT_VALUE_CHAN GED: java.awt.TextFi eld[LNAME,116,142,2 30x31,invalid,t ext=Quixote,edi table,selection =0-0]
TEXT_VALUE_CHAN GED: java.awt.TextFi eld[FNAME,116,173,2 30x31,invalid,t ext=Don,editabl e,selection=0-0]
What I want:

LOADING...
TEXT_VALUE_CHAN GED: java.awt.TextFi eld[LNAME,116,142,2 30x31,invalid,t ext=Quixote,edi table,selection =0-0]
TEXT_VALUE_CHAN GED: java.awt.TextFi eld[FNAME,116,173,2 30x31,invalid,t ext=Don,editabl e,selection=0-0]
LOADED.

Any ideas? I'm going mad here!
Jul 17 '05 #1
2 2313
cd*@milhouse.sg iscpq.com (C. Armour) wrote in message news:<86******* *****@milhouse. sgiscpq.com>...
Help me, I'm suffering!

Situation: I have a load() function which loads a bunch
of TextFields with values. There are TextListeners
registered for each of these TextFields. Thus, changing the
text in any of them fires off a TextEvent, even if done
programmaticall y (by means of setText()).

The problem: I need all the various TextEvents fired off
during the load operation (as a result of using TextField.setTe xt())
to be handled BEFORE the load() function completes. In other words,
load() must hang around waiting for all these events to have been
handled by somehow blocking on a state variable.

Some code:

public void load()
{
System.out.prin tln("LOADING... ");

lname.setText(" Quixote");
fname.setText(" Don");

System.out.prin tln("LOADED.");


Change this line to:

SwingUtilities. invokeAndWait(n ew Runnable() {
public void run() {
System.out.prin tln("LOADED.");
}
});

This will ensure that the Event Dispatching Thread has processed all
pending events prior to printing out the text. invokeLater will also
work in this case, since you don't have anything after the second
print that needs to happen synchronously.

Greg
Jul 17 '05 #2
>>>>> "Gregory" == Gregory A Swarthout <gr******@xmiss ion.com> writes:

Gregory> Change this line to:

Gregory> SwingUtilities. invokeAndWait(n ew Runnable() { public
Gregory> void run() { System.out.prin tln("LOADED."); } });

Gregory> This will ensure that the Event Dispatching Thread has
Gregory> processed all pending events prior to printing out the
Gregory> text. invokeLater will also work in this case, since you
Gregory> don't have anything after the second print that needs to
Gregory> happen synchronously.

Hey, thanks. That's exactly what I was looking for.

Of course, I'm not using Swing, but it should work, right?
cda

Jul 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
6421
by: Joseph | last post by:
hi 1) i plan on having an awt canvas component (to draw graphs) on a JFrame with other swing components..will this be okay? i've read that swing and awt aren't compatible.. 2)Also, if i have a function which simply loops infinately that is part of a form, what happens when a form event (eg button click) occurs? will the event handler be executed simulatanesouly with the loop? or does the event excecute first and then the loop is...
0
1806
by: linux newbie | last post by:
is there any java expert could tell me what the problem below and explain the code to me, your explanation is greatly appreciated :) static Class class$java$awt$event$ActionListener; static Class _mthclass$(String x$0) { try
3
5620
by: Sidney Linkers | last post by:
Hi, I'm trying to make a calculated text field in a query where the textvalue is being populated from multiple records. I already use a VBA function to loop through records and concatenate the text. It works but the performance is really bad. I'm looking for a solution in plane SQL, so the looping is done by joining tables. I can't get it to work....
0
1270
by: turkmen38 | last post by:
hi every one i am new to java and object oriented programming.my problem is that i wanna acces a text field...in a frame i created a text area and a button.i want to populate textarea when the button is clicked..i know it is very simple to you but i have been struggling with this for hours.....below is the source code... thanx in advance ---------------------- /* * i am trying to populate a textfield or textarea when a button is...
2
1109
Awt
by: shana07 | last post by:
Hi all, I have few questions about AWT, please feel free to comment....TIA 1. What is AWT? 2. Is there anything to do between AWT & Image java program? 3. Is AWT also built in package in JAVA? Please point to me any links how to use AWT.
12
1981
by: -Lost | last post by:
In Firefox and Safari for example, if I serve my XHTML documents as application/xml or xhtml+xml they only display the top inch or so of the document. In Opera it says "object has been blocked." In Internet Explorer of course you get total rubbish. Anything from "page cannot be loaded" to "403 no permission." The thing is, I figured the first two at least could handle it, maybe
0
1776
by: adamselearning | last post by:
Hi... I've followed Colin Moock's AS3 notes to create a VirtualPet I've got it working from the code at: http://www.adobe.com/devnet/actionsc...n_moock_f6.pdf ...but am now trying to add a textField on the stage that will display the % of calories remaining. Extra code I have created in VirtalPet.as: 1. private var petView (An instance of VirtualPetView) 2. petView.displayInfo() (Called from the digest() method, which is called by...
1
2052
by: mlibot | last post by:
hello... how to get the current path of the directory and it will display on the textfield... this is my codes: private void BrowseDirActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: JFileChooser JFileChooseDir = new JFileChooser(); JFileChooseDir.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
0
10206
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10035
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9984
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9851
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8863
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7403
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6662
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5441
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2811
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.