Solved

How to change the size of JButton in GridLayout

Posted on 2010-08-12
7
819 Views
Last Modified: 2012-05-10
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
0
Comment
Question by:Danielohm
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 16

Accepted Solution

by:
Valeri earned 168 total points
ID: 33422902
try this :
Dimension btnDim = new Dimension(40, 18);
abc.setPreferredSize(btnDim);
0
 
LVL 16

Expert Comment

by:Valeri
ID: 33422924
if it doesn't work, try with setMinimumSize(btnDim);
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 33423398
You might be better off changing the panel size. The buttons will simply fill it equally to the maximum extent
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 92

Assisted Solution

by:objects
objects earned 332 total points
ID: 33425591
> 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
 
LVL 92

Assisted Solution

by:objects
objects earned 332 total points
ID: 33426995
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
 
LVL 27

Expert Comment

by:mrcoffee365
ID: 37105852
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In this post we will learn different types of Android Layout and some basics of an Android App.
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Suggested Courses

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question