midipedalTest.setSelected(false);
In the early part of the code you posted, the ONLY action taken when execution exited the loop was the above. Why bother with a loop if the code that sets the flag that allows the loop to exit could have executed the above statement. The flag and the loop are not needed.