I want to add a Lable in a JComponent when a button will be clicked. I have added a actionlistner on that button.
I've added this.add(label) in the JComponent. but the location, which is set by label.setLocation(...) is not maintained in the JComponent. If i use FlowLayout() in the JComponent then the labels are added from the top of the area of the JComponent. If I use BorderLayout then only one Label can be added upon a Button click.
So what kind of JComponent configuration allows me to add a JLabel at exactly the position mentioned by me?
I've also used "null" Layout, but then no Labels can be added.
So what should I do?
I'm adding some of my codes for understanding.
this the JComponent PadDraw()
public PadDraw()
{
setDoubleBuffered(false);
setLayout(new FlowLayout());
}
below code is a method in the PadDraw JComponent which is invoked when a button is pressed :
private void add_instances()
{
for(instance_struct comps : counts.components)
{
comps.label.setLocation(comps.x_pos,comps.y_pos);
this.add(comps.label);
}
}