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
Flowlayout
Use GridBagLayout instead of FlowLayout.
GridBagLayout
JPanel panel=new JPanel(); panel.setLayout(new GridBagLayout()); panel.add(new JButton("Sample")); // will use default value of GridBagConstraints