K
Kerry Shetline
If I've not yet laid out a component, say a JTextField, and use
getPreferredSize() to find the preferred width, I'll get what I'd
expect to get: a width which is just wide enough for the text in the
field.
Now, suppose I set the width to something wider than this preferred
width, via setBounds() or setSize(). If I again use getPreferredSize()
to find the preferred width, I'll now get the width I just set, rather
than what I originally got from getPreferredSize().
How, if it's at all possible, do I ask a component "If I'd never
changed your size before, what size would you now prefer to be?"?
What I'm aiming at is a layout where excess window width is
distributed among expandable columns. When the window is reduced in
width, I don't want the colums which have been expanded to be "stuck"
at the expanded width -- I want to be able to shrink those columns
back down to the widest *original* preferred width of any component in
each column.
So far I've only created layouts such as this by ignoring a
component's preferred width, and letting the width go as low as 1 if
the containing window is shrunk sufficiently.
As a hack, I can save the first preferred width I get, but that not's
only inelegant, but wouldn't work well if the component's content
changed dynamically.
In the case of a JTextField, using getMinumumSize() doesn't seem to be
helpful... it returns a width less than that needed to display the
full text.
getPreferredSize() to find the preferred width, I'll get what I'd
expect to get: a width which is just wide enough for the text in the
field.
Now, suppose I set the width to something wider than this preferred
width, via setBounds() or setSize(). If I again use getPreferredSize()
to find the preferred width, I'll now get the width I just set, rather
than what I originally got from getPreferredSize().
How, if it's at all possible, do I ask a component "If I'd never
changed your size before, what size would you now prefer to be?"?
What I'm aiming at is a layout where excess window width is
distributed among expandable columns. When the window is reduced in
width, I don't want the colums which have been expanded to be "stuck"
at the expanded width -- I want to be able to shrink those columns
back down to the widest *original* preferred width of any component in
each column.
So far I've only created layouts such as this by ignoring a
component's preferred width, and letting the width go as low as 1 if
the containing window is shrunk sufficiently.
As a hack, I can save the first preferred width I get, but that not's
only inelegant, but wouldn't work well if the component's content
changed dynamically.
In the case of a JTextField, using getMinumumSize() doesn't seem to be
helpful... it returns a width less than that needed to display the
full text.