Solved

how to identifiy JTextField object at runtime, since the reference name is not stored at class file?

Posted on 2007-03-18
5
260 Views
Last Modified: 2007-03-18
hello experts,

understand that for below code:
  JTextField field1 = new JTextField();

field1 will not be stored inside the class file, but only at source code file.

Then how could I identify this object at runtime? In other words, is there any way to give id to "field1" object that can be read at runtime by other codes  (since the reference name "field1", will not be stored at runtime)

Or should I override JTextField into a new class and create a new attributes for id? Is there any for the existing JTextField?

Thanks & regards.
0
Comment
Question by:isuhendro
5 Comments
 

Author Comment

by:isuhendro
ID: 18743341
btw to clarify..
for example

at class A i have code like below:

JPanel myPanel = new JPanel();
JTextField field1  = new JTextField();
JTextField field2  = new JTextField();

myPanel.add(field1);
myPanel.add(field2);

my question is related to an inner class, named class B, inside class A.
Inside class B, I am trying to write code which will return a collection whose members are a pair of fieldname and its value, e.g ("field1", "valueoffield1"), ("field2", "valueoffield2").
The problem is as i told you, i could not get the id "field1", "field2", etc
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 18744098
You could call getComponents on the nearest Container to the JTextField(s) to which you want to get a reference
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 18744536
You can expose it as a member of the class A:

public JTextField getFirstTextField ()
{
  return field1 ;

}

You can either expose all of them this way (using multiple get methods) to be accessible from outside or create them in an array and expose the array in one method.
0
 
LVL 92

Accepted Solution

by:
objects earned 125 total points
ID: 18745049
0
 
LVL 92

Expert Comment

by:objects
ID: 18745053
eg.  field.setName("field1");
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How to get all the API from website? 11 104
What's wrong with this code? 4 26
Problem to Alipay 10 43
How to configure empty element in XML Document parser? 15 36
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question