JInternalFrame's order of additoin



The following two produces different results:

desktopPane.add(internalFrame);
internalFrame.setVisible(true);
System.out.println(Arrays.asList(desktopPane.getAllFrames()));

when runned three times the order is.:
1
1,2
2,1,3

internalFrame.setVisible(true);
desktopPane.add(internalFrame);
System.out.println(Arrays.asList(desktopPane.getAllFrames()));

when runned three times the order is.:
1,
2,1
3,2,1


where 1, 2, 3 are the object's value and title.


which way is correct?


.