Re: A JLabel's Size
- From: Knute Johnson <nospam@xxxxxxxxxxxxxxxxxxxxxxx>
- Date: Wed, 07 Mar 2007 15:35:04 -0800
A. Bolmarcich wrote:
On 2007-03-07, Jason Cavett <jason.cavett@xxxxxxxxx> wrote:On Mar 7, 11:45 am, Knute Johnson <nos...@xxxxxxxxxxxxxxxxxxxxxxx>
wrote:
Jason Cavett wrote:Something I'm curious about...The component has to be realized first. It gets realized when the
When I create a JLabel and place it into a JPanel/JDialog/some other
component, it always appears as the correct size (just large enough to
display the text + appropriate boundary around the text). But, when I
attempt to get that JLabel's size, it returns 0 width and 0 height
unless I specifically set the size of the JLabel.
Shouldn't the size have been set correctly upon the addition of the
text to the label? I'm confused on how this is working and why it's
working that way.
container it is in is either packed or its size is set.
Excuse the quibble, but the size of the component is set by pack() as
a side effect of pack() validating (laying out) the Window. Validating
a Container causes the LayoutManager of the Container to set the sizes
of the Components in the Container. (I'll skip the detail of the
Window being made displayable.)
Not a quibble, you are correct. pack() or setVisible() are the correct conditions.
--
Knute Johnson
email s/nospam/knute/
.
- References:
- A JLabel's Size
- From: Jason Cavett
- Re: A JLabel's Size
- From: Knute Johnson
- Re: A JLabel's Size
- From: Jason Cavett
- Re: A JLabel's Size
- From: A. Bolmarcich
- A JLabel's Size
- Prev by Date: Re: Saving/Restoring state
- Next by Date: Re: a naive question
- Previous by thread: Re: A JLabel's Size
- Index(es):
Relevant Pages
|