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

L

lucy

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
 
A

Andrew Thompson

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*.
 
T

Tor Iver Wilhelmsen

lucy said:
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.
 
L

lucy

Tor Iver Wilhelmsen said:
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.


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...
 
F

Frank

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...

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.
 
L

lucy

Frank said:
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.


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?

---------------------------------------------------
 
L

Liz

lucy said:
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

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();
============
 
A

Adam

lucy said:
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?

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top