-1

I'm having trouble with a Slider for a Volumecontrol.

Atm I use FloatControl to handle the MasterVolume of an Audioclip, bad for me I need a new ChangeListener for every new AudioClip - so i tried this:

JSlider slider_Vol // the Object i use the whole time
JSlider tempSlider // a temporary used Slider i create in an other function

if (slider_Vol.getChangeListeners() != null)            
  slider_Vol.removeChangeListener(slider_Vol.getChangeListeners()[0]); //Array[0] correct position?

slider_Vol.addChangeListener(tempSlider.getChangeListeners()[0]);

it seems like my If dont work, because there is allready an exceptions for the remove command when the program starts and no changelistener was created.

Any ideas?

Skandix
  • 1,916
  • 6
  • 27
  • 36

1 Answers1

1

try changing the statement to:

ChangeListener listener;
if (!slider_Vol.getChangeListeners().length == 0){
    listener = slider_Vol.getChangeListeners()[0]
    slider_Vol.removeChangeListener(slider_Vol.getChangeListeners()[0]);
} else {
    listener = new ChangeListener[your code];
}
slider_Vol.addChangeListener(listener);
Angelo Alvisi
  • 480
  • 1
  • 4
  • 15
  • great, this solved the Problem with the if (....length !=0) any idea how the do a bether copy, because the change listener added after this is never called if i run the project – Skandix Jan 17 '15 at 13:24
  • it somehow dont copy the right ChangeListener, dont realy know why.... is "slider.getChangeListerners()[0]" realy the rigth call for this? – Skandix Jan 17 '15 at 16:48
  • I don't know, not enough of your code is shown. If you are having problems with arrays you should probably try some basic Java tutorials first. – Angelo Alvisi Jan 17 '15 at 17:01