JTextArea Size  
Author Message
Kevin Munro





PostPosted: 2003-12-3 18:53:00 Top

java-programmer, JTextArea Size Hello, I'm writing a java app for a pda and as the screen size is tiny I
want to write a MiniDialog class. I only want a JTextArea and an OK button
on it and I want the JTextArea to fit the size of the modal dialog.

If I pass in a long line of text then the JTextArea appears to get wider and
I have to scroll across the screen to see the text. I want it to wrap onto
the second line etc.

I must be doing something stupid!

Thanks, Kevin.

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class MiniDialog {

JDialog dialog=new JDialog(new JFrame(),"Info",true);

public MiniDialog() { }

public void show(String label) {
Container c=dialog.getContentPane();

JButton ok=new JButton("OK");
dialog.getRootPane().setDefaultButton(ok);

ok.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
dialog.dispose();
}
});

JTextArea txt=new JTextArea(5,20);
txt.setEditable(false);
txt.append(label);

JScrollPane scroll=new JScrollPane(txt);
scroll.setSize(1,1);

dialog.setSize(200,200);
dialog.setLocation(20,40);
c.add(scroll,BorderLayout.CENTER);
c.add(ok,BorderLayout.SOUTH);
dialog.show();
}
}


 
Alex Hunsley





PostPosted: 2003-12-3 19:10:00 Top

java-programmer >> JTextArea Size Kevin Munro wrote:

> Hello, I'm writing a java app for a pda and as the screen size is tiny I
> want to write a MiniDialog class. I only want a JTextArea and an OK button
> on it and I want the JTextArea to fit the size of the modal dialog.
>
> If I pass in a long line of text then the JTextArea appears to get wider and
> I have to scroll across the screen to see the text. I want it to wrap onto
> the second line etc.
>
> I must be doing something stupid!
>
> Thanks, Kevin.
[snip]

try doing setLineWrap(true) on the JTextArea.

alex


 
Alex Hunsley





PostPosted: 2003-12-3 19:16:00 Top

java-programmer >> JTextArea Size Alex Hunsley wrote:

> Kevin Munro wrote:
>
>> Hello, I'm writing a java app for a pda and as the screen size is tiny I
>> want to write a MiniDialog class. I only want a JTextArea and an OK
>> button
>> on it and I want the JTextArea to fit the size of the modal dialog.
>>
>> If I pass in a long line of text then the JTextArea appears to get
>> wider and
>> I have to scroll across the screen to see the text. I want it to wrap
>> onto
>> the second line etc.
>>
>> I must be doing something stupid!
>>
>> Thanks, Kevin.
>
> [snip]
>
> try doing setLineWrap(true) on the JTextArea.

Also, when you post code in the future, can you please post a fully
working selfcontained version? What you posted lacked a main method so
can't be run to test it (unless someone writes a main method).

alex

 
 
nos





PostPosted: 2003-12-17 23:22:00 Top

java-programmer >> JTextArea Size Working on a new app. with

output = new JTextArea(3, 45); // rows columns

How much data can I send to it using append

output.append("Your screen width is 1024.\n");

before it is full?
TIA


 
 
usenet





PostPosted: 2003-12-18 22:53:00 Top

java-programmer >> JTextArea Size nos <email***@***.com> wrote:
> Working on a new app. with
>
> output = new JTextArea(3, 45); // rows columns
>
> How much data can I send to it using append
>
> output.append("Your screen width is 1024.\n");
>
> before it is full?



Integer.MAX_VALUE - 1 characters.



Christian
--
And in short, I was afraid.