Solved

How to change the size of JButton in GridLayout

Posted on 2010-08-12
7
769 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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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 26

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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
factorial example challenge 10 61
countPairs challenge 7 58
topping2 challenge 13 59
Unable to start eclipse ? 17 83
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…

707 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now