I am trying to write a class to perform a certain action on each component in a JFrame
.
My idea was to use the method getComponents
and then access to the elements of the array that it returns, as shown in the following code
/*window is the JFrame that I am using, while Player1, Player2 ... are all JLabel or JTextField*/
primaryStage.add(Player1);
primaryStage.add(Player2);
primaryStage.add(playerInput);
primaryStage.add(score);
primaryStage.add(timeLeft);
primaryStage.repaint();
Component[] components = window.getComponents();
float scaleFactorX = window.getWidth() / initialWidth;
float scaleFactorY = window.getHeight() / initialHeight;
Arrays.stream(components).forEach( /*performs action on each component*/);
However the array components seems to contain no elements other than the JFrame
itself. I have also tried revalidating, but it doesn't work. Any ideas?