Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.gui > #1392
| From | "A. Bolmarcich" <a..bolmarcich@THRWHITE.remove-dii-this> |
|---|---|
| Subject | Re: How to prevent a long |
| Message-ID | <slrnf18ch4.28n9.aggedor@earl-grey.cloud9.net> (permalink) |
| Newsgroups | comp.lang.java.gui |
| References | <1175721430.203113.150600@l77g2000hsb.googlegroups.com> |
| Date | 2011-04-27 15:33 +0000 |
| Organization | TDS.net |
To: comp.lang.java.gui
On 2007-04-04, martinog2@gmail.com <martinog2@gmail.com> wrote:
> Hi All,
>
> I want to have a long JLabel, but I dont want my entire dialog to be
> sized based on this long JLabel -- I want the JLabel to wrap, & I want
> the dialog size to be set by other controls.
[snip]
> With this, I can get the effect I want. To see it, I change the size
> of the JTextField. JTextField(10) -- it wraps. JTextField(80) -- it
> doesnt wrap. Thats good.
>
> I got it to work like this with this line:
> label.setPreferredSize(new Dimension(0, 100));
>
> The problem is the height. For the width, I can use '0' and it will
> size correctly. I cant do the same with height. If I set it to '0' (or
> -1, 1, 2, etc) then thats the height it uses. With '100', its ok when
> the text field is small, but when its big, theres too much vertical
> space around the label.
>
> I dont know how to say:
> 'set a preferred width, but leave the preferred height alone'
You say that by writing and using a class that extends JLabel that
overrides the getPreferredSize() method to be like
Dimension getPreferredSize() {
return newDimension(WIDTH_YOU_WANT, super.getPreferredSize().height);
}
> Or
> 'set preferred width to 0 (and you'll later re-adjust that),
> and set preferred height to the height after you've wrapped it'
This can be done by a more complicated getPreferredSize() method
that can somehow determine what its width will be set to (say,
by getting the preferred width of the JTextField in the same
column) and then determine what its height should be for that width.
---
* Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet!
--- Synchronet 3.15a-Win32 NewsLink 1.92
Time Warp of the Future BBS - telnet://time.synchro.net:24
Back to comp.lang.java.gui | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
How to prevent a long JLa "martinog2" <martinog2@THRWHITE.remove-dii-this> - 2011-04-27 15:33 +0000 Re: How to prevent a long "A. Bolmarcich" <a..bolmarcich@THRWHITE.remove-dii-this> - 2011-04-27 15:33 +0000 Re: How to prevent a long "visionset" <visionset@THRWHITE.remove-dii-this> - 2011-04-27 15:33 +0000 Re: How to prevent a long "Daniel Pitts" <daniel.pitts@THRWHITE.remove-dii-this> - 2011-04-27 15:33 +0000 Re: How to prevent a long "martinog2" <martinog2@THRWHITE.remove-dii-this> - 2011-04-27 15:33 +0000
csiph-web