I need to rearrange items that are in my GridLayout so when a JButton is created dynamically, that the footer (i.e. JLabel) stays at the bottom of the grid, and the dynamically created button goes right above the footer.
Is this possible? If so can I see an example, please?
My grid currently is a
new GridLayout(intIndex, 1);
where intIndex is incremented every time a dynamic element is created.
Since it’s a footer, you probably want to use
BorderLayoutand keep the footer down at the bottom withBorderLayout.PAGE_END. Then put your component with theGridLayoutin the center withBorderLayout.CENTER. This way, your footer will always remain at the bottom and it won’t interfere with the content, which you’re now free to change to use any layout manager without affecting the footer.This should be a good fix if your footer spans across the whole bottom, but if you’re trying to make some sort of small footer in the bottom corner, then it’ll be a little more difficult, but either way I’d suggest trying to keep the footer separate from the content.