Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / August 2004

Tip: Looking for answers? Try searching our database.

known Java frame, how to get handle to a edit control box?

Thread view: 
lucy - 19 Aug 2004 20:42 GMT
Hi all Java gurus,

I have a question: suppose I know a Java frame, how can I get the handle to
an edit box contained on this Java frame...

And I want to know the content string of this edit box each time user enter
a key into this editor box... How to do that?

Thank you very much,

(please help me a little detailed... I am a VC programmer and know very
little of Java programming... can anybody give some sample code?)

-Lucy
Andrew Thompson - 19 Aug 2004 21:14 GMT
> I have a question: suppose I know a Java frame,

Do you 'know' it in the bibblical sense?
Do you have the code?
Do you have the JavaDocs?

>..how can I get the handle to
> an edit box contained on this Java frame...
>
> And I want to know the content string of this edit box each time user enter
> a key into this editor box... How to do that?

It all depends on the answers to the above
questions.  Well, not so much the first maybe..

> (please help me a little detailed... I am a VC programmer and know very
> little of Java programming... can anybody give some sample code?)

Do you have some sample code (of the Java program you speak)?

BTW - Posting to three groups ..
<comp.lang.java.programmer,comp.lang.java.help,comp.lang.java.gui>
..for a question of this nature is too many,
<http://www.physci.org/codes/javafaq.jsp#xpost>
..and you should not generally cross-post from
c.l.j.help to *either* of the other two groups.

Please restrict you questions to c.l.j.help for the moment..

Follow-ups set to c.l.j.help *only*.

Signature

Andrew Thompson
http://www.PhySci.org/ Open-source software suite
http://www.PhySci.org/codes/ Web & IT Help
http://www.1point1C.org/ Science & Technology

Tor Iver Wilhelmsen - 19 Aug 2004 21:24 GMT
> I have a question: suppose I know a Java frame, how can I get the handle to
> an edit box contained on this Java frame...

If it's a public variable, just access it via the frame object, e.g.
yourFrame.theField; However, be aware this is bad OO design; only the
frame containing the field should really care about the text field.

> And I want to know the content string of this edit box each time
> user enter a key into this editor box... How to do that?

A DocumentListener on the Document of the "edit box" - provided you
are talking about Swing.
lucy - 19 Aug 2004 21:55 GMT
> > I have a question: suppose I know a Java frame, how can I get the handle to
> > an edit box contained on this Java frame...
[quoted text clipped - 8 lines]
> A DocumentListener on the Document of the "edit box" - provided you
> are talking about Swing.

I don't have the code,

but I did get an object of the frame:

here is the object name: very strange!

com.mathworks.hg.peer.FigurePeer@10e9c03

Is this a AWT or Swing?

then what can I do with it?

I want to know the content of the edit field on this frame object in Java...
Frank - 19 Aug 2004 22:18 GMT
>> > I have a question: suppose I know a Java frame, how can I get the  
>> handle
[quoted text clipped - 25 lines]
> I want to know the content of the edit field on this frame object in  
> Java...

This sounds like AWT, since the Peers for Swing classes will mostly use  
strictly LightWeightPeer.

Having said this, holding onto the Peer of a component is very bad  
style... this is generally an internal reference for comunication with the  
OS, and not the public java ref you want.

Find the JavaDocs for the code you're asking about, and you'll probably  
find your answer.
lucy - 20 Aug 2004 01:08 GMT
> >> > I have a question: suppose I know a Java frame, how can I get the
> >> handle
[quoted text clipped - 35 lines]
> Find the JavaDocs for the code you're asking about, and you'll probably
> find your answer.

Hi,  here is the message I've post to the mathworks forum; as you can see,
they won't give me their javadoc, I guess...

And in Matlab there is no way to get the updated string content of the edit
control...

any more ideas? Please help me!

Thank you very much

---------------------------------------------------------

Hi all,

I am using Matlab7 to design my GUI.

Suppose I have a Edit control "A"

I want to check the data input validity of this edit control "A".

Can I use its "Callback Fcn"? No.

Because it does not be triggered at the right time. Only when the mouse make
the Edit control "A" lose focus, this "Callback Fcn" will be triggered...

This is bad, because on my GUI, I don't have other GUI controls to let the
focus to move to that control.

Do I need to stupidly ask the user to click mouse on any other part of the
window in order to let the edit Control "A" lose focus?

Do I need to stupidly add a button "check me" to ask the user press that
button in order to let the edit control "A" lose focus and then I can
retrieve its value in that "Callback fcn" in order to check its value..

That's stupid, right?

Can I use the "Keypressed Fcn" callback?

No!

The KeypressFcn callback is always triggered before the content of the edit
control is updated... so the content retrieved in the KeypressFcn callback
is always an older version, instead of the new updated string. So this
function basically is of no use at all.

Now these two functions are of no use all, how do I check the user's input
upon each key is entered?

Anybody has some workarounds?

---------------------------------------------------
Cid - 20 Aug 2004 01:53 GMT
>> > I don't have the code,
>> >
[quoted text clipped - 10 lines]
>> > I want to know the content of the edit field on this frame object in
>> > Java...

You might try using Reflection to find out what this creature is made
of. With your reference, o:
1. Get o's class, c. ie: Class c = o.getClass()
2. Print c.getName()
3. Get c's super class: c = c.getSuperclass()
4. repeat from #2 until c is null

This will at least give you some more info about what this thing is
and where it came from. One of those classes should eventually
identify what it is (awt or swing component) and from there you'd can
deal with it based on that base class's well defined interface.

Or you could just use reflection to list all the methods on o directly
(check out the Class api). But that would likely involve reading a
_very_ long list.
Andrew Thompson - 20 Aug 2004 02:50 GMT
> This will at least give you some more info about what this thing is
> and where it came from.

For more details..
<http://groups.google.com/groups?th=43acda034f3027ef>

I suspect Steve Eddins knows a great deal
more about it.. Information he is apparently
prepared to impart.  (Given he works for the
company that made it).

Signature

Andrew Thompson
http://www.PhySci.org/ Open-source software suite
http://www.PhySci.org/codes/ Web & IT Help
http://www.1point1C.org/ Science & Technology

Liz - 20 Aug 2004 02:39 GMT
> > > "Tor Iver Wilhelmsen" <tor.iver.wilhelmsen@broadpark.no> wrote in
> message
[quoted text clipped - 49 lines]
>
> Thank you very much

I don't know how far you have to go with this but I
use getParent() as often as necessary. You can do it
once then check if you need to do more. You can use
jdb to tell you what type of container you have at each
step. In the code below, I have a reference to some Panel
that is displayed in a JDialog.
HTH
============
Container p0 = ((MREFERENCES[group]).getParent());
Container p1 = p0.getParent();
Container p2 = p1.getParent();
Container p3 = p2.getParent();
((JDialog)p3).toFront();
============
> ---------------------------------------------------------
>
[quoted text clipped - 38 lines]
>
> ---------------------------------------------------
Adam - 20 Aug 2004 07:41 GMT
> Hi all Java gurus,
>
[quoted text clipped - 3 lines]
> And I want to know the content string of this edit box each time user enter
> a key into this editor box... How to do that?

WHat do you know about the editbox?
There will be a problem if there is more than one
on the frame.

Now, are you sure that the object you have is a Frame object?
We know that it exact class is com.mathworks.hg.peer.FigurePeer,
how do you know it is a Frame? I doubt that (looking at the class
name).

Well, you better check with (obj instanceof java.awt.Frame).
If this expression returns true, you are almost there.
You have to cast the object to Frame and use Frame
methods to enumerate its child components
(Frame.getComponents()), each of obtained
components can be a Container, check it (with instanceof again),
and if it is - collect its child components as well (do you see
the recursion?). Once you're done with collecting all components
you can iterate through them checking which is a TextField
(instanceof). Once you get a reference to a TextField,
add some listeners to it (check javadocs for an appropriate one).

If there is only one TextField on the Frame - no problem,
but what if threre's more than one... which to choose?

That was for AWT, in case of Swing you would do:
- check if obj is a JFrame
- if so, getContentPane of the JFrame
- recursively collect child components of the content pane (same as
above)
- check each against JTextField

But it looks like you have a peer component, not a Java (J)Frame...
Can't help you here.

Adam


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.