Skip to main content

More flexible min/max/preferred width and height for components

3 replies [Last post]
Joined: 2003-08-12

At the moment there is not way to say to the layout managers that a JComponent should have a certain min/max/preferred width but no min/max/preferred height (that I know of anyway). This makes some kinds of layout managers hard to implement without resorting to layout context objects, which would be somewhat redundant.

Add (to JComponent):

<br />
setPreferredWidth(Integer w)<br />
setPreferredHeight(Integer h)</p>
<p>setMinimumWidth(Integer w)<br />
setMinimumHeight(Integer h)</p>
<p>settMaximumWidth(Integer w)<br />
setMaximumHeight(Integer h)<br />

(+ get versions of above.)

Null means 'unspecified' or 'whatever'.

Also add the interconnected versions:

<br />
Integer getPreferredWidth(int ifHeight)<br />
Integer getPreferredHeight(int ifWidth)</p>
<p>Integer getMinimumWidth(int ifHeight)<br />
Integer getMinimumHeight(int ifWidth)</p>
<p>Integer getMaximumWidth(int ifHeight)<br />
Integer getMaximumHeight(int ifWidth)<br />

It would open up for situations where, for instance, preferred height is a function of the preferred width. A text component for instance could answer the question 'What would be your preferred height given the width of 100 '.

Making this interact transparently with the current API is quite simple. It wouldn't break code that 'doesn't know' about this feature, yet new Layout Managers could be written that used them.

Mikael Grev

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Joined: 2004-10-14

That would be really useful. I always wondered why it was not part of Java 1.0/1.2 (for AWT/Swing). Having to extend a button or any other component just to be able to set its size because layout managers will ignore it otherwise is so annoying and illogical.


Joined: 2003-06-28

Yes, this sounds like a good feature, and might resolve some problems with layouting text component. Mind filing an RFE for it?

Joined: 2003-08-12

Did it, done it.

You [b]really[/b] have to make that system more modern though. Feels like stone age. Filing an RFE as a bug feels like an afterthought.

I'll post a separate about it. :)

Mikael Grev