Results 1 to 10 of 10

Thread: Color and date

  1. #1
    sadist_g22 is offline Member
    Join Date
    May 2014
    Posts
    4
    Rep Power
    0

    Default Color and date

    Hello everyone ,
    I am working on a chat programme and I was wondering how to separate the both usernames for example:
    Server is me , and Client is the first man who had connected to me , so I want to be
    Server to be in green color , and Client to be in Red
    Server(green):Hi
    Client(red):hello
    Server(green):How you doin'
    Client(red):Fine
    .........
    my second question is both of em' to have minutes and dates for example
    27.05.2014 11:30pm Server(green):Hi
    27.05.2014 11:31pmClient(red):hello
    27.05.2014 11:32pmServer(green):How you doin'
    27.05.2014 11:33pmClient(red):Fine

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,572
    Rep Power
    25

    Default Re: Color and date

    Where are the lines being displayed? Some classes have techniques for setting colors.

    See the SimpleDateFormat class for ways to format a date to a String.
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    sadist_g22 is offline Member
    Join Date
    May 2014
    Posts
    4
    Rep Power
    0

    Default Re: Color and date

    I've tried with setForeground(Color.red) but it tells me it can't be used with string , please help me :)

  4. #4
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,783
    Rep Power
    5

    Default Re: Color and date

    I recommend you look at using JTextAreas for you chat windows. They can be formatted in a variety of ways. The link for the tutorials is in my signature below.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  5. #5
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,572
    Rep Power
    25

    Default Re: Color and date

    Where and how are the Strings being displayed? String objects do not have a color.
    If you don't understand my response, don't ignore it, ask a question.

  6. #6
    sadist_g22 is offline Member
    Join Date
    May 2014
    Posts
    4
    Rep Power
    0

    Default Re: Color and date

    well when I write chatWindow.setForeground(color.blue); for example the my username and the other turns into blue , i Want only my to turn into blue and the other want for example in red :)

  7. #7
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,572
    Rep Power
    25

    Default Re: Color and date

    What is the class you are using to display the Strings? Is it one of the following? Which one?
    JPanel
    JTextfield
    JTextArea
    JTextPane
    ????
    If you don't understand my response, don't ignore it, ask a question.

  8. #8
    sadist_g22 is offline Member
    Join Date
    May 2014
    Posts
    4
    Rep Power
    0

    Default Re: Color and date

    JTextArea

  9. #9
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,572
    Rep Power
    25

    Default Re: Color and date

    The background colors can be set using a Highlighter.
    If you don't understand my response, don't ignore it, ask a question.

  10. #10
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,783
    Rep Power
    5

    Default Re: Color and date

    Can you please create a small, compilable program where you are writing to the JTextArea and trying to change colors? Then post the code here.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

Similar Threads

  1. Replies: 5
    Last Post: 02-16-2012, 09:26 AM
  2. Replies: 4
    Last Post: 07-27-2011, 11:57 AM
  3. Replies: 2
    Last Post: 05-12-2011, 04:52 PM
  4. Compare date input to database with current date
    By hungleon88 in forum Advanced Java
    Replies: 2
    Last Post: 11-25-2008, 08:10 AM
  5. Creating a Gregorian Calendar using a Date object gives date - 1
    By prachi_goliwadekar in forum New To Java
    Replies: 1
    Last Post: 05-08-2008, 08:32 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
  •