Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > JTextArea Size

Reply
Thread Tools

JTextArea Size

 
 
Kevin Munro
Guest
Posts: n/a
 
      12-03-2003
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();
}
}


 
Reply With Quote
 
 
 
 
Alex Hunsley
Guest
Posts: n/a
 
      12-03-2003
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


 
Reply With Quote
 
 
 
 
Alex Hunsley
Guest
Posts: n/a
 
      12-03-2003
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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
JTextArea preferred size Christopher Benson-Manica Java 1 02-09-2009 11:32 PM
Preferred Size, Minimum Size, Size Jason Cavett Java 5 05-25-2008 08:32 AM
mega pixels, file size, image size, and print size - Adobe Evangelists Frank ess Digital Photography 0 11-14-2006 05:08 PM
JTextArea size nos Java 1 12-18-2003 02:53 PM
Tab key on JTextArea Ahmed Moustafa Java 1 06-28-2003 03:25 PM



Advertisments