What i tried addes button to the end of box.
Yes, the add(component)
method just adds the component to the end of the container.
If you want to add the component to the beginning then you need to specify an index value of 0. Read the Container API for the appropriate method. I don't remember if it is add(component, index)
or add(index, component)
.
Then once you add the component you need to invoke
panel.revalidate();
panel.repaint();