Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / October 2005

Tip: Looking for answers? Try searching our database.

styles in a JTextPane..

Thread view: 
Frances Del Rio - 04 Oct 2005 20:54 GMT
this is for an IM window..

I need to do equivalent of sthg like this:

<span class="uid">Username: </span><span class="msgBody">this is my
message</span>
  <span style="leftRoom">UserX has left the room</span>...
    (only attr's that change are font COLORS, all other attr's remain
the same from style to style..)

I'm basically trying to do what I found in these two pgs..
http://javaalmanac.com/egs/javax.swing.text/style_HiliteWords2.html
http://javaalmanac.com/egs/javax.swing.text/tp_StyledText.html

so:
     Color fontColor = new Color(31,92,159);
     Color fontColorUid = new Color(9,121,30);    

 Style uid = textAreaTop.addStyle("a", null);
 StyleConstants.setForeground(uid, fontColorUid);

  Style msgBody = textAreaTop.addStyle("b", null);
 StyleConstants.setForeground(uid, fontColor);

     String sUid = "myName: ";
     String msg =  textAreaBottom.getText();
     textAreaBottom.setText("");
   
     try {
  doc.insertString(doc.getLength(), sUid, uid);
  }  catch(BadLocationException e) {
    System.out.println("Exception Caught: " + e.getMessage() + "
[BadLocation Exp] " + e);
        }
        try {
  doc.insertString(doc.getLength(), msg, msgBody);
  }  catch(BadLocationException e) {
    System.out.println("Exception Caught: " + e.getMessage() + "
[BadLocation Exp] " + e);
        }

it's printing same color font for both styles..
(SO MUCH CODE to change JUST font COLOR..)

also need to know here....

 Style uid = textAreaTop.addStyle("a", null);
      // "a" is name of style? Style already named here..
                //  Style uid...  don't get what params go
                // in parens in this method...
               // since create new 'uid' style before '='...
 StyleConstants.setForeground(uid, fontColorUid);

thank you very much.. this is proving quite a challenge...

Frances
Frances Del Rio - 04 Oct 2005 21:12 GMT
> this is for an IM window..
>
[quoted text clipped - 52 lines]
>
> Frances


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.