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


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

Re: JTextArea size proble

From "Larry Barowski" <larry.barowski@THRWHITE.remove-dii-this>
Subject Re: JTextArea size proble
Message-ID <StWdnbpw8sYzhpPanZ2dnUVZ_jWdnZ2d@comcast.com> (permalink)
Newsgroups comp.lang.java.gui
References <HohPi.47$Bu.20@newsfe17.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:HohPi.47$Bu.20@newsfe17.lga...
> Larry Barowski wrote:
>> "Knute Johnson" <nospam@rabbitbrush.frazmtn.com> wrote in message 
>> news:J0hOi.159$TF.70@newsfe13.lga...
>>> I also included an example that works just fine with a JTextArea.
>>
>> Of course you can get it to work if you know ahead of time
>> how many lines the wrapped text will require. That is unlikely
>> in a real-world situation, and was not the case in the example
>> in the OP.
>>
>>
>
> He said it was two lines.

The error message was passed in as a parameter to the error dialog
constructor, so it would be reasonable to assume he wanted a solution
that works for any length of text. Besides, unless the number of rows
are fixed and the width flexible or the text is one character long, the
number of wrapped lines for any text in any component that wraps
text in any gui layout is always system dependent in principle.

>  If you want it to do any number of lines then you have to call pack() 
> again after you know how many lines it will take.

I have already posted two solutions that are equivalent to the one
below.

> import java.awt.*;
> import java.awt.event.*;
> import javax.swing.*;
>
> public class test10 {
>     public static void main(String[] args) {
>         Runnable r = new Runnable() {
>             public void run() {
>                 final JFrame f = new JFrame();
>                 f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
>                 JButton b = new JButton("press me one more time");
>                 b.addActionListener(new ActionListener() {
>                     public void actionPerformed(ActionEvent ae) {
>                         JDialog d = new JDialog(f,true);
>                         JTextArea ta = new JTextArea(
>                          "Enough text to wrap and be visible on two 
> lines");
>                         ta.setColumns(15);
>                         ta.setLineWrap(true);
>                         d.add(ta);
>                         d.pack();
>                         ta.setRows(ta.getLineCount());
>                         d.pack();
>                         d.setLocationRelativeTo(f);
>                         d.setVisible(true);
>                         d.dispose();
>                     }
>                 });
>                 f.add(b);
>                 f.pack();
>                 f.setVisible(true);
>             }
>         };
>         EventQueue.invokeLater(r);
>     }
> }
>
> -- 
>
> Knute Johnson
> email s/nospam/knute/

---
 * 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