Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.gui > #2582

Re: JTextArea size proble

From "Larry Barowski" <larry.barowski@THRWHITE.remove-dii-this>
Subject Re: JTextArea size proble
Message-ID <ftKdnZ040MnVIZ7anZ2dnUVZ_o6knZ2d@comcast.com> (permalink)
Newsgroups comp.lang.java.gui
References <470376e5$0$13927$fa0fcedb@news.zen.co.uk>
Date 2011-04-27 15:39 +0000
Organization TDS.net

Show all headers | View raw


  To: comp.lang.java.gui

"RedGrittyBrick" <redgrittybrick@spamweary.foo> wrote in message 
news:470376e5$0$13927$fa0fcedb@news.zen.co.uk...
> In a dialogue box, I want to display some text word-wrapped. I use a 
> JTextArea and set word wrapping on.
>
> However, the height of the dialogue seems to be incorrectly based on the 
> Textarea being one line high, (it is two lines high when wrapped).

During layout, the text area doesn't know what its eventual width will
be, so it has no way to provide a useful preferred height. It's a problem
for any component for which the preferred size in one dimension
depends on the actual size in the other. This might be good enough to
solve your problem (replacement for pack()):

  pack();
  messageComponent.setSize(messageComponent.getPreferredSize());
  pack();

You could write your own word-wrapping label class from scratch,
but there is no way to solve the basic problem of height/width
dependence. A double pack(), at least, would still be required.

---
 * 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 | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

JTextArea size problem. "RedGrittyBrick" <redgrittybrick@THRWHITE.remove-dii-this> - 2011-04-27 15:39 +0000
  Re: JTextArea size proble "Larry Barowski" <larry.barowski@THRWHITE.remove-dii-this> - 2011-04-27 15:39 +0000
  Re: JTextArea size proble "Roedy Green" <roedy.green@THRWHITE.remove-dii-this> - 2011-04-27 15:40 +0000

csiph-web