JTextArea Size

Discussion in 'Java' started by Kevin Munro, Dec 3, 2003.

  1. Kevin Munro

    Kevin Munro Guest

    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();
    }
    }
     
    Kevin Munro, Dec 3, 2003
    #1
    1. Advertising

  2. Kevin Munro

    Alex Hunsley Guest

    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, Dec 3, 2003
    #2
    1. Advertising

  3. Kevin Munro

    Alex Hunsley Guest

    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
     
    Alex Hunsley, Dec 3, 2003
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ahmed Moustafa

    Tab key on JTextArea

    Ahmed Moustafa, Jun 28, 2003, in forum: Java
    Replies:
    1
    Views:
    2,819
    xarax
    Jun 28, 2003
  2. bad_knee
    Replies:
    0
    Views:
    535
    bad_knee
    Jul 13, 2003
  3. nos

    JTextArea size

    nos, Dec 17, 2003, in forum: Java
    Replies:
    1
    Views:
    645
    Christian Kaufhold
    Dec 18, 2003
  4. Jason Cavett

    Preferred Size, Minimum Size, Size

    Jason Cavett, May 23, 2008, in forum: Java
    Replies:
    5
    Views:
    12,654
    Michael Jung
    May 25, 2008
  5. Christopher Benson-Manica

    JTextArea preferred size

    Christopher Benson-Manica, Feb 9, 2009, in forum: Java
    Replies:
    1
    Views:
    1,515
    Knute Johnson
    Feb 9, 2009
Loading...

Share This Page