Solved

JLabel Sizing

Posted on 2006-11-02
5
653 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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
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 …
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

747 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

17 Experts available now in Live!

Get 1:1 Help Now