Results 1 to 7 of 7
  1. #1
    Krooger is offline Member
    Join Date
    Nov 2008
    Posts
    43
    Rep Power
    0

    Question JTextArea Wrap Around or something?

    Hello, I'm trying to set an area in my GUI that will display information as required. This area is a textured Panel so I want this text area to be see through.

    The closest I have gotten is using a JTextField and setting opaque to false but I can only get the text to go in a stright line and not wrap around once it gets to the edge of the text field

    So basicaly I need a see through box area that I can add text to and it will stay within the boxed area.

    Any tips on what I should be looking at?

    Thank You

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

  3. #3
    Krooger is offline Member
    Join Date
    Nov 2008
    Posts
    43
    Rep Power
    0

    Default

    Heh funny I ment to write JTextField in the title, anyways Im playing with this code at the moment:
    Java Code:
    JTextArea actionP = new JTextArea("ABCDEFGHIJKLMNOPQ");
    		actionP.setOpaque(false);
    		actionP.setBorder(null);
    		actionP.append(" MORE AND MORE AND MORE AND MORE");
    		Dimension textDim = new Dimension((int)(actionPanelRight.getWidth()*0.85), (int)(actionPanelRight.getHeight()*0.8));
    		actionP.setPreferredSize(textDim);
    		actionPanelRight.setLayout(new GridBagLayout());
    		actionP.setForeground(Color.white);
    		actionPanelRight.add(actionP);
    		actionPanelRight.validate();
    What happens is once the string get the same length as the JTextArea it just keeps going off the screen, I need it to wrap onto the next line. The reason is that I don't quite know what strings to expect but I do need them to fit in a certain width whereas I have lots of height to work with.

  4. #4
    camickr is offline Senior Member
    Join Date
    Jul 2009
    Posts
    1,233
    Rep Power
    6

    Default

    I need it to wrap onto the next line.
    Read the JTextArea API to find the appropriate methods used to turn on wrapping.

  5. #5
    Krooger is offline Member
    Join Date
    Nov 2008
    Posts
    43
    Rep Power
    0

    Default

    actionP.setLineWrap(true);
    :) Thank You I don't know why I didn't come across that before. Do you have any advice on how to prevent a word from being half at the end of a line and the rest of it being at the start of the next line? Just dosent look very nice.

  6. #6
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    There's one more method worth looking in to, and the API for the method above should link to it: setWrapStyleWord

  7. #7
    camickr is offline Senior Member
    Join Date
    Jul 2009
    Posts
    1,233
    Rep Power
    6

Similar Threads

  1. Word Wrap not functioning correctly?
    By zerkz in forum New To Java
    Replies: 2
    Last Post: 10-08-2009, 06:41 PM
  2. Eclipse import line wrap
    By bogomips in forum Eclipse
    Replies: 0
    Last Post: 11-26-2008, 04:16 PM
  3. How to create tool bar (wrap on resize)
    By Java Tip in forum SWT
    Replies: 0
    Last Post: 07-02-2008, 08:10 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •