how do i create new JLabel() dynamically in a while loop, and add to a JPanel by using the setBounds method. The setBounds work, however, there are other JLabel added to other place. why is this happen?

while(condition){
                pin = new JLabel();
        	pin.setIcon(pinIcon);
        	pin.setBounds(Panel1.getImgX(), Panel1.getImgY(), 20, 30);
        	Panel1.panel.add(pin);
}

nobody can understood that from this code snipped, (look for Insets, not Bounds)

revalidate();
repaint();

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.