How to change the size of JButton in GridLayout

Hi, all expert

I am stuck in changing the cell size of
JButton[] abc = new JButton[49];
which is added in JPanel midPanel = new JPanel(new GridLayout(7,7))

Is there a way to change the size JButton ?
The each cell size of JButton seems to be determined by some default value.
Thank you.

Daniel
DanielohmAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ValeriCommented:
try this :
Dimension btnDim = new Dimension(40, 18);
abc.setPreferredSize(btnDim);
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ValeriCommented:
if it doesn't work, try with setMinimumSize(btnDim);
0
CEHJCommented:
You might be better off changing the panel size. The buttons will simply fill it equally to the maximum extent
0
Build an E-Commerce Site with Angular 5

Learn how to build an E-Commerce site with Angular 5, a JavaScript framework used by developers to build web, desktop, and mobile applications.

Mick BarryJava DeveloperCommented:
> The each cell size of JButton seems to be determined by some default value.

the space available is divided equally between each cell.
You can decrease the amount of space taken up by each button by adding a border to the button

button.setBorder(BroderFactory.createEmptyBorder(10, 10, 10, 10));
0
Mick BarryJava DeveloperCommented:
if you want control over the size of individual buttons then you may need to use a different layout manager as GridLayout sizes each cell equally
0
mrcoffee365Commented:
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.