Results 1 to 3 of 3
  1. #1
    droidus is offline Senior Member
    Join Date
    Feb 2011
    Posts
    244
    Rep Power
    4

    Default alternating font color

    i would like to alternate my font color. the code that i have right now changes all of the text. how can i get it so that it will only update one line color at a time, rather than the whole text area font?

    Java Code:
    private void sendTextActionPerformed(java.awt.event.ActionEvent evt) {
    		String temp = input.getText() + "\n";
    
    		if (toggleUser.getSelectedItem().equals("User 1")) {
    			update1.setForeground(Color.red);
    			update1.append(temp);
    		} else if (toggleUser.getSelectedItem().equals("User 2")) {
    			update1.setForeground(Color.BLUE);
    			update1.append(temp);
    		}
    	}

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,310
    Blog Entries
    7
    Rep Power
    20

    Default Re: alternating font color

    A JTextArea can't do that (it uses the 'font color' for all the text). Have a look at the JTextArea class or the JEditorPane class.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

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

Similar Threads

  1. PdfBox font color
    By BobswYourUcle in forum New To Java
    Replies: 1
    Last Post: 07-13-2011, 05:04 AM
  2. Replies: 0
    Last Post: 08-18-2010, 10:31 AM
  3. font color
    By newbie123 in forum New To Java
    Replies: 2
    Last Post: 03-01-2010, 03:58 PM
  4. Replies: 5
    Last Post: 04-25-2009, 08:00 PM
  5. to set toolItem font color
    By vidyakkk in forum SWT / JFace
    Replies: 0
    Last Post: 01-30-2009, 03:06 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
  •