Re: Handling private jtextfields




Jl_G_0 wrote:
Hey all. Trying a simple script here, but I have no idea on how to do
this.
I'm trying to create a script like this:

void setValue(String strName, String strText){
[strName].setText(strText);
}

let me explain:
strName should be converted to a JTextField (of course its not done
right there), I mean, I'll send the text field name as a parameter,
and I want to know if there's some function that searches my
components and returns the one with the same name as strName so I can
set its value.

In c#/asp.net I could use a function to search through my
components(foreach control c in page.controls...) , so its another way
to do it, IF I knew how to do this in java.

Is there any way that I can make this work ? Thanks.

You want to retrieve a reference to a JTextField by 'name' ?

Here's an idea or two, may be way off base.

You have a JPanel. MyJPanel
and you want to add 20 JTextFields to it.

String nameJTextField1 = "JTEXTFIELD1"
JTextField jTextField1 = new JTextField();

MyJPanel.add(jTextField1);

Map<String, JTextField> textfieldMap =
new HashMap<String, JTextField>();

textfieldMap.put(nameJTextField1, jTextField1);

void setValue(String strName, String strText){
textfieldMap.get(strname).setText(strText);
}

Or ask the Container for a list of Components it contains.

Component[] ca = MyJPanel.getComponents()
for(Component c : ca) {
if(it's the Component you want)
doSomething();
}

Or maybe even better use the java.awt Event system.




.



Relevant Pages

  • Re: Saving to a specific file with a specific file name
    ... Dim strName As String ... 'Remove cell marker from string ... ChangeFileOpenDirectory (strPath) ...
    (microsoft.public.word.vba.general)
  • Re: INSERT INTO statement
    ... Dim StrSQL as String ... Dim strName As String ... O Wilson wrote: ...
    (microsoft.public.access.gettingstarted)
  • revise my code
    ... public static void main (String[] args) ... public void actionPerformed ... public class Form1 extends JFrame implements ActionListener ... JTextField text1; ...
    (comp.lang.java.programmer)
  • revise this code
    ... public static void main (String[] args) ... public void actionPerformed ... public class Form1 extends JFrame implements ActionListener ... JTextField text1; ...
    (comp.lang.java.programmer)
  • Re: Referencing subform during module code
    ... This would work at the form level, but not at the subform. ... Dim strName As String ...
    (comp.databases.ms-access)