473,383 Members | 1,958 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

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
programmatically (by means of setText()).

The problem: I need all the various TextEvents fired off
during the load operation (as a result of using TextField.setText())
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.addTextListener(this);
fname.addTextListener(this);

load();
}

public void textValueChanged(TextEvent e)
{
System.out.println(paramString() + ": " + e.getSource().toString());
}

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

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

System.out.println("LOADED.");
}
}

Some output:

LOADING...
LOADED.
TEXT_VALUE_CHANGED: java.awt.TextField[LNAME,116,142,230x31,invalid,text=Quixote,editable ,selection=0-0]
TEXT_VALUE_CHANGED: java.awt.TextField[FNAME,116,173,230x31,invalid,text=Don,editable,sel ection=0-0]
What I want:

LOADING...
TEXT_VALUE_CHANGED: java.awt.TextField[LNAME,116,142,230x31,invalid,text=Quixote,editable ,selection=0-0]
TEXT_VALUE_CHANGED: java.awt.TextField[FNAME,116,173,230x31,invalid,text=Don,editable,sel ection=0-0]
LOADED.

Any ideas? I'm going mad here!
Jul 17 '05 #1
2 2280
cd*@milhouse.sgiscpq.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
programmatically (by means of setText()).

The problem: I need all the various TextEvents fired off
during the load operation (as a result of using TextField.setText())
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.println("LOADING...");

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

System.out.println("LOADED.");


Change this line to:

SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
System.out.println("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******@xmission.com> writes:

Gregory> Change this line to:

Gregory> SwingUtilities.invokeAndWait(new Runnable() { public
Gregory> void run() { System.out.println("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
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...
0
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; ...
3
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...
0
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...
2
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?...
12
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."...
0
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...
1
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) { ...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.