By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,313 Members | 1,240 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,313 IT Pros & Developers. It's quick & easy.

JLabel - setSize

100+
P: 144
hi,

i have a JLabel inside a JPanel of which layout manager is BoxLayout. i will display an image with the JLabel at runtime,

when the application first start, it will appear as an empty box with border. i've set the border for the JLabel, but then it appears as a small rectangle, i've tried to use the setSize and the setMinimumSize but still it appears so small. how to make it be displayed with a fixed size even if it's empty (contains no text).


thank you very much.
Oct 17 '08 #1
Share this Question
Share on Google+
6 Replies


MarkoKlacar
Expert 100+
P: 296
Hi,

Does it have to be a JLabel? Try an ImageIcon, my experiece with images and JLabels is not that pleasant.

/MK
Oct 20 '08 #2

Expert 10K+
P: 11,448
Hi,

Does it have to be a JLabel? Try an ImageIcon, my experiece with images and JLabels is not that pleasant.

/MK
An AWT container can only contain Components; an ImageIcon isn't a Component.
You do have to use a Component that is able to contain some form of a picture.
A JLabel is a good option.

kind regards,

Jos
Oct 20 '08 #3

chelvan
P: 90
hi
try like this

Expand|Select|Wrap|Line Numbers
  1. JLabel lbl1=new JLabel(new image("image.jpg"));
  2.  
regards
chel-1
Oct 21 '08 #4

10K+
P: 13,264
hi
try like this

Expand|Select|Wrap|Line Numbers
  1. JLabel lbl1=new JLabel(new image("image.jpg"));
  2.  
regards
chel-1
Read Jos' post above about ImageIcon again.
Oct 21 '08 #5

chelvan
P: 90
Read Jos' post above about ImageIcon again.
so
can i change the code like this
Expand|Select|Wrap|Line Numbers
  1. JLabel lbl1=new JLabel(new ImageIcon("image.jpg"));
  2.  
chel-1
Oct 22 '08 #6

10K+
P: 13,264
so
can i change the code like this
Expand|Select|Wrap|Line Numbers
  1. JLabel lbl1=new JLabel(new ImageIcon("image.jpg"));
  2.  
chel-1
What happens when you try that? I hope you have the specs for JLabel and ImageIcon open with you for reference as you try these things.
Oct 22 '08 #7

Post your reply

Sign in to post your reply or Sign up for a free account.