Solved

How to change the size of JButton in GridLayout

Posted on 2010-08-12
7
838 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
What Is Transaction Monitoring and who needs it?

Synthetic Transaction Monitoring that you need for the day to day, which ensures your business website keeps running optimally, and that there is no downtime to impact your customer experience.

 
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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
In this post we will learn different types of Android Layout and some basics of an Android App.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

724 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