Solved

JLabel Sizing

Posted on 2006-11-02
5
657 Views
Last Modified: 2008-02-26
I basically have an application in which I want to use Jlabels in as tiles.  I want to create a 4x4 grid of JLabels that contain one letter each.

ahdf
idus
ywnf
oapd

Something like that.  I have my labels rendering onto my window except I can't seem to change the size of the labels.  The Labels seem to stay the size of the letter no matter what size i specify with setSize.  I was wondering how I would go about making all of the labels squares.  Each square would have a letter in the middle and the blank space would be filled with a background color.

If anyone could help me out it would be greatly appreciated.


Thanks

~Matthew
0
Comment
Question by:Zeman4323
  • 2
5 Comments
 
LVL 14

Accepted Solution

by:
hoomanv earned 63 total points
ID: 17864498
Try setPrefferedSize() using null layout
or simply use GridLayout
0
 
LVL 2

Assisted Solution

by:glottis
glottis earned 62 total points
ID: 17864598
You can use the setPrefferedSize, with the functionality of setting the font size of your labels.

JLabel label = new JLabel("A");
label.setPrefferedSize(new Dimension(50, 50));
Font f = label.getFont();
f.setSize(<your preffered size of the font>); //i thing this is the method name
label.setFont(f);

regards,
0
 
LVL 14

Expert Comment

by:hoomanv
ID: 17864616
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

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…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
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 …
The viewer will learn how to implement Singleton Design Pattern in Java.

911 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

25 Experts available now in Live!

Get 1:1 Help Now