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


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

Re: JTextArea size proble

From "Larry Barowski" <larry.barowski@THRWHITE.remove-dii-this>
Subject Re: JTextArea size proble
Message-ID <VNCdnQRJken4UZnanZ2dnUVZ_qainZ2d@comcast.com> (permalink)
Newsgroups comp.lang.java.gui
References <TMTMi.66425$hP1.52602@newsfe13.lga>
Date 2011-04-27 15:40 +0000
Organization TDS.net

Show all headers | View raw


  To: comp.lang.java.gui

"Knute Johnson" <nospam@rabbitbrush.frazmtn.com> wrote in message 
news:TMTMi.66425$hP1.52602@newsfe13.lga...
> Larry Barowski wrote:
>>> A simple solution for multi-line component is to use a JLabel and put 
>>> HTML in it.
>>
>> That has the same problem, if you put in enough text for wrap
>> to occur. There is no way for a component to work around this.
>>
> JTextAreas layout funny there are a lot of issues.  The program below uses 
> a JDialog with a JLabel in it and it sizes just fine.

Yes, but your example uses a label with 3 forced lines of text and
no wrapping. The problem is not with JTextArea, it is with laying
out a component for which the preferred width is flexible and
preferred height depends on width, or vice versa. If a component
can fit the text "exactly" at 4000x10, 200x200, 50x800, and lots
of sizes in between, what should it report for its preferred size?
What should it do when it doesn't get it? Lets say it chooses
200x200...

component: I want to be 200x200.
layout manager: The row you are in will be 400 pixels wide,
   as will you.
component: In that case, I only need to be 100 pixels high.
layout manager: Too late.
programmer: What's this big empty space?

To see this general behavior, add
   messageComponent.setSize(50, Integer.MAX_VALUE)
before the pack() in RGB's original example above.

My solution above would do this:

component: I want to be 200x200.
layout manager: The row you are in will be 400 pixels wide,
   as will you.
component: In that case, I only need to be 100 pixels high.
layout manager: Too late.
program: OK, lets go again, with the knowledge that component
   should be 400 pixels wide.

Which might be more obvious if you code it this way:

pack();
messageComponent.setSize(messageComponent.getWidth(),
               Integer.MAX_VALUE);
pack();

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


Thread

Re: JTextArea size proble "Larry Barowski" <larry.barowski@THRWHITE.remove-dii-this> - 2011-04-27 15:40 +0000

csiph-web