let me ask you a question. I have a folder with pictures in different sizes, from that I read a picture randomly, reduce its size and deduce using a JLabel on a jpanel - it's simple. The fact that the withdrawal of one picture can be displayed at the right coordinates, and the other can bounce on the meter.Why does it happen? Random pictured ignore SetBounds and bounds of other containers.
private void initialize() throws IOException {
frame = new JFrame();
frame.setBounds(100, 100, 1150, 664);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().setLayout(null);
panel = new JPanel ();
panel.setBounds(10, 10, 1150, 664);
frame.getContentPane().add(panel);
File f = new File ("C:/Users/user/Desktop/Ramms");
String[] names = f.list();
all_Images= new ImageIcon[names.length];
for(int i=0; i<names.length; i++){
all_Images[i]= new ImageIcon ("C:/Users/user/Desktop/Ramms/"+names[i]);
}
selected_Image = all_Images[random(0,all_Images.length)];
w= selected_Image.getIconWidth()/scl;
h= selected_Image.getIconHeight()/scl;
Image img = selected_Image.getImage();
bic = new BufferedImage(img.getWidth(null), img.getHeight(null), BufferedImage.TYPE_INT_ARGB);
Graphics g = bic.createGraphics();
g.drawImage(img, 0, 0, w, h, null);
newIcon = new ImageIcon(bic);
panel.setLayout(null);
JLabel label1 = new JLabel(newIcon);
panel.add(label1).setBounds(0,100,w,h);
}