How can I set a component (say button) at center of the panel?
I used Flowlayout
with layout constraint as center, but I am getting button at top-center position of the panel.
How can I set a component (say button) at center of the panel?
I used Flowlayout
with layout constraint as center, but I am getting button at top-center position of the panel.
This can be achieved using either GridBagLayout
as mentioned by AVD1 or BoxLayout
. See this answer for sample code.
Personally I'd use GBL for this because fewer lines of code are required to get the component laid out & on-screen (centered in the parent container).