JTextArea fun...

Discussion in 'Java' started by theCassman@googlemail.com, Nov 7, 2006.

  1. Guest

    Hi,

    I am wanting to have an area of text which will take in sets of
    coordinates and display them straight away. Initially, i used a
    JTextArea and simply used the .append() method to add the newest
    coordinates to the end of the current text. This worked perfectly fine.

    However, my problem now is that i want, at some points, one set of
    coordinates to display in a different colour to the rest. I.e. The
    selected object would have its coordinates highlighted in the text
    area. Due to the fact that .setForeground() changes the colour of the
    entire contents of the JTextArea; i need to use something else. I have
    tried using a JTextPane but cannot work out how to make it append extra
    information like the JTextArea does.

    Does anybody have any suggestions on what i could use to 1) display
    text as i add new objects and 2) have the ability to have different
    coloured text. Cheers.

    Regards,

    Cassman
     
    , Nov 7, 2006
    #1
    1. Advertisements

  2. Oliver Wong Guest

    <> wrote in message
    news:...
    > Hi,
    >
    > I am wanting to have an area of text which will take in sets of
    > coordinates and display them straight away. Initially, i used a
    > JTextArea and simply used the .append() method to add the newest
    > coordinates to the end of the current text. This worked perfectly fine.
    >
    > However, my problem now is that i want, at some points, one set of
    > coordinates to display in a different colour to the rest. I.e. The
    > selected object would have its coordinates highlighted in the text
    > area. Due to the fact that .setForeground() changes the colour of the
    > entire contents of the JTextArea; i need to use something else. I have
    > tried using a JTextPane but cannot work out how to make it append extra
    > information like the JTextArea does.
    >
    > Does anybody have any suggestions on what i could use to 1) display
    > text as i add new objects and 2) have the ability to have different
    > coloured text. Cheers.


    I don't understand what you're trying to do, but if you want different
    coloured text, you'll need to use a styled-text component (or write your own
    component). See
    http://java.sun.com/docs/books/tutorial/uiswing/components/editorpane.html

    - Oliver
     
    Oliver Wong, Nov 7, 2006
    #2
    1. Advertisements

  3. Daniel Pitts Guest

    wrote:
    > Hi,
    >
    > I am wanting to have an area of text which will take in sets of
    > coordinates and display them straight away. Initially, i used a
    > JTextArea and simply used the .append() method to add the newest
    > coordinates to the end of the current text. This worked perfectly fine.
    >
    > However, my problem now is that i want, at some points, one set of
    > coordinates to display in a different colour to the rest. I.e. The
    > selected object would have its coordinates highlighted in the text
    > area. Due to the fact that .setForeground() changes the colour of the
    > entire contents of the JTextArea; i need to use something else. I have
    > tried using a JTextPane but cannot work out how to make it append extra
    > information like the JTextArea does.


    jTextPane.setText(jTextPane.getText() + newText);

    >
    > Does anybody have any suggestions on what i could use to 1) display
    > text as i add new objects and 2) have the ability to have different
    > coloured text. Cheers.
    >
    > Regards,
    >
    > Cassman


    You might also want to use a JList instead, as this seems more like
    what you want.
     
    Daniel Pitts, Nov 7, 2006
    #3
  4. Guest

    Cheers guys, i will try both of these.

    Regards,

    Cassman
     
    , Nov 7, 2006
    #4
    1. Advertisements

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,935
    xarax
    Jun 28, 2003
  2. bad_knee
    Replies:
    2
    Views:
    724
    bad_knee
    Jul 14, 2003
  3. Thomas Weidenfeller

    Re: JTextArea text is double-spaced?

    Thomas Weidenfeller, Jul 16, 2003, in forum: Java
    Replies:
    2
    Views:
    620
    Thomas Weidenfeller
    Jul 17, 2003
  4. Brian J. Sayatovic
    Replies:
    0
    Views:
    2,189
    Brian J. Sayatovic
    Sep 7, 2003
  5. Brett Sheeran

    Unable To Change Color In JTextArea

    Brett Sheeran, Sep 13, 2003, in forum: Java
    Replies:
    3
    Views:
    9,967
    Illuvian
    Jul 4, 2006
  6. Andy Fish
    Replies:
    65
    Views:
    2,334
    Mabden
    May 18, 2004
  7. dolphin
    Replies:
    4
    Views:
    571
    Jorgen Grahn
    Aug 25, 2007
  8. er
    Replies:
    2
    Views:
    800
Loading...