0

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);
}

Edited by peter_budo: Keep It Clear - Do wrap your programming code blocks within [code] ... [/code] tags

2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by mKorbel
0

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

revalidate();
repaint();

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.