argh, sorry for the crossposts, here's the correct one

I have some code in a for loop that creates a certain number of JTextfields directly to the right of JSliders. Each JSlider has an anonymous inner class with a listener. So what I do on the listener is just go through the array and test if the corresponding JSlider is equal to the source of the event. Then I write the value in the Slider to the JTextField with the array index equal to the index that I figured out comparing JSliders to the JSlider source. Basically, I know I have the correct index and the correct value, but it doesn't show up in the JTextField. Here's my code segment.

for(int i=0;i<numSliders;i++){

if(((JSlider)(ce.getSource())).equals(sliderArray[i])){

fieldArray[i].setText(Integer.toString(((JSlider)(ce.getSource())).getValue()));

fieldArray[0].setText("hi");//this doesn't even work

System.out.println(i);//this prints the right index every time

System.out.println(Integer.toString(((JSlider)(ce.getSource())).getValue()));//this prints the right value every time

}//end of if

}//end of for

>

[1476 byte] By [zachvaca] at [2007-10-1 0:34:46]
# 1

> fieldArray[0].setText("hi"); //this doesn't even work

That isn't very precise. However I will assume the following:

1. There are some JTextFields visible in your GUI.

2. You believe that line of code should cause one of them to display "hi".

Then it looks like fieldArray[0] refers to a JTextField that isn't visible for some reason.

Or perhaps you meant that line of code didn't compile? Some explanation and details would help.

DrClapa at 2007-7-7 16:21:57 > top of Java-index,Security,Event Handling...
# 2
And it would be nice if, when you accidentally post duplicates, you would add a reply to the duplicates (saying that's what they are) so that no one wastes their time answering them.
ChuckBinga at 2007-7-7 16:21:57 > top of Java-index,Security,Event Handling...
# 3

sorry about the duplicates. I discovered the problem and solution. Thanks to all who helped. The problem was at the start of the class I had

private JTextField fieldArray[]=null

And then I initialized it fine and added the correct listener. After that I did:

fieldArray[i] = new JTextField();

Obviously that presented a problem. It's fixed now and thanks again to all who helped.

zachvaca at 2007-7-7 16:21:57 > top of Java-index,Security,Event Handling...