Solved

How to change the size of JButton in GridLayout

Posted on 2010-08-12
7
807 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
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Which non-HTML GUI front end to use with Java? 3 50
jboss 7.1 start up error 1 60
going to wrong jsp page 2 46
java example issue 5 42
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

685 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