473,387 Members | 1,501 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

JLabel - setSize

144 100+
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
6 6042
MarkoKlacar
296 Expert 100+
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
JosAH
11,448 Expert 8TB
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
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
r035198x
13,262 8TB
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
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
r035198x
13,262 8TB
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

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

Similar topics

1
by: prabhat | last post by:
Hi, I am getting this weird behavior. I have couple of gif and jpg files that I would like to display in JLabel. It displays one jpg image but it does not display other gifs and jpgs. Any idea why...
1
by: Phil... | last post by:
I have the following code to put a label on a tabbed panel. It does not set the background though. If I put in a "slabel.getBackground()" it returns the color I chose for the set. It is like the...
0
by: Mike | last post by:
Hello, Is there a way of setting text for a JLabel after a certain amount of empty characters. For example, I want to avoid doing this JLabel label = new JLabel(); label.setText(" ...
2
by: reon | last post by:
Hi in this code when i clicked login button...it shows output as login... But when i clicked each time its repeating .. i want to see that only ones ... I want to clear the previous login before...
5
Shinzon
by: Shinzon | last post by:
ok so far I have got: JFrame frame = new JFrame( "Matt's DVD's" ); frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE ); frame.setSize( 420, 170 ); // set frame size ...
5
Shinzon
by: Shinzon | last post by:
Ok so I have been working on this for a moment now and wondering how to add multiple jlabels to a jframe. the code looks like this: JLabel jl = new JLabel("DVD ID #= " + dvd); //Displays DVD...
3
nanhiPari
by: nanhiPari | last post by:
hello everyone i need to create DYNAMIC JLABElS(say 5)..yes i know it sounds easy but i also have to give them Events n then want to refer each of them when ever Mouse is Clicked on a Specific...
1
by: tommyny04 | last post by:
I have a method addPlayer that's supposed to add a JLabel to a JPanel and update the JPanel. The JLabel is just a label with a player's name in it. The code I've wrote doesn't work and I'm not sure...
2
by: Coreyja | last post by:
Im trying to display a png image by setting it as a ImageIcon and then putting that in a JLabel. I cant get it to display the image. I am using a null layout as it is the simplest way for me to get...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.