Solved

How to change the size of JButton in GridLayout

Posted on 2010-08-12
7
792 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
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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
how to add new optional parameter to JSP 1 49
servlet filter example 37 71
ejb mdb examples 1 6
running on tomcat not jboss eap 7.0 3 17
An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
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…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

765 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