How to print diffrent color and diffrent size of text in JTextArea ?

Hello All,
i want to make JFrame which have JTextArea and i append text in
JTextArea in diffrent size and diffrent color and also with diffrent
fonts.
any body give me any example or help me ?
i m thanksfull.
Arif.

You can't have multiple text attributes in a JTextArea.
JTextArea manages a "text/plain" content type document that can't hold information about attributes ( color, font, size, etc.) for different portions of text.
You need a component that can manage styled documents. The most basic component that can do this is JEditorPane. It can manage the following content types :
"text/rtf" ==> via StyledDocument
"text/html" ==> via HTMLDocument
I've written for you an example of how a "Hello World" string could be colorized in a JEditorPane with "Hello" in red and "World" in blue.
import javax.swing.JEditorPane;
import javax.swing.text.StyleConstants;
import javax.swing.text.StyledEditorKit;
import javax.swing.text.StyledDocument;
import javax.swing.text.MutableAttributeSet;
import javax.swing.text.SimpleAttributeSet;
import java.awt.Color;
public class ColorizeTextTest{
     public static void main(String args[]){
          //build gui
          JFrame frame = new JFrame();
          JEditorPane editorPane = new JEditorPane();
          frame.getContentPane().add(editorPane);
          frame.pack();
          frame.setVisible(true);
          //create StyledEditorKit
          StyledEditorKit editorKit = new StyledEditorKit();
          //set this editorKit as the editor manager [JTextComponent] <-> [EditorKit] <-> [Document]
          editorPane.setEditorKit(editorKit);
          StyledDocument doc = (StyledDocument) editorPane.getDocument();
          //insert string "Hello World"
          //this text is going to be added to the StyledDocument with positions 0 to 10
          editorPane.setText("Hello World");
          //create and attribute set
          MutableAttributeSet atr = new SimpleAttributeSet();
          //set foreground color attribute to RED
          StyleConstants.setForeground(atr,Color.RED);
          //apply attribute to the word "Hello"
          int offset = 0; //we want to start applying this attribute at position 0
          int length = 5; //"Hello" string has a length of 5
          boolean replace = false; //should we override any other attribute not specified in "atr" : anwser "NO"
          doc.setCharacterAttributes(offset,length,atr,replace);
          //set foreground color attribute to BLUE
          StyleConstants.setForeground(atr,Color.BLUE);
          //apply attribute to the word "World"
          offset = 5; //we include the whitespace
          length = 6;
          doc.setCharacterAttributes(offset,length,atr,replace);
}

Similar Messages

  • How to print both letter and legal size docs at same time with two trays

    I have an HP Laser Jet P2055dn printer. How can I print both letter and legal docs at same time?

    Not quite sure what you mean by "print both letter and legal docs at same time".
    If you mean that sometimes you want to print a document on Letter size paper, and at other times you want to print a different document on Legal sized paper, then all that is neccessary is to ensure that:
    The printer knows what Paper Size (e.g. Letter or Legal) is present in each tray; on many LaserJet devices, the size is detected automaticaly by sensors in each tray (except for the drop-down tray), but some devices may require that you set the size via front panel menus, or (for network models) via the Embedded Web Server equivalent.
    You may also need to specify what Paper Type (e.g. Plain or Letterhead) is present in each tray, in order to distinguish between two or more trays which have the same paper size loaded.
    Within your appllcation / print preferences, ensure that you select the required combination of size and type for the document.
    But if you mean how do you print a document with some pages on one size of paper, and other pages on a different size, this may only be possible with bespoke applications and/or printer drivers.

  • I have many photos with file extension of .PDD and that Photo Deluxe 4 no longer will operate in Win 7. How can I open?  Next in Elements 11, how do I load and print different pictures and different sizes options on the same page?

    I have many photos with file extension of .PDD and that Photo Deluxe 4 no longer will operate in Win 7. How can I open?  Next in Elements 11, how do I load and print different pictures and different sizes options on the same page?
    Thanks,
    Shir

    sbmgrams wrote:
    I have many photos with file extension of .PDD and that Photo Deluxe 4 no longer will operate in Win 7. How can I open?
    See here:
    Reading PhotoDeluxe PDD Files

  • HT4356 How can I print a greyscale/fast document from my iPad wireless printer. It will print in color and high quality but want black and white

    How can I print a greyscale/black and white document from my iPad wireless printer???
    IT will print in COLOR and high quality print but would like to conserve ink (Esp. Coloured )
    is there a way to reconfigure settings either on my iPad or the printer ??? Cannot find a setting
    when u select print on the ipad it dos not allow you to change your settings before you print

    There is no setting for this. You can request it here:
    http://www.apple.com/feedback/

  • How can I export to PDF for Offset printing including color and grayscale photo's?

    After reading dozens of forum, I still don’t found the answer.
    I made a photobook with full-colur and B/W photos for Offset printing. I want the B/W to be in grayscale to avoid color possible color shades. It seems InDesign doesn’t support grayscale, the images become way to dark. Even with exporting without any colour conversion or destination and/or including original colour profiles, the grayscale pictures are being exported to dark to PDF.
    How can I export to PDF for Offset printing including color and grayscale photo’s?

    Yes, the Photoshop & ID CMYK working spaces are the same
    This can get difficult because the 3 programs handle soft proofing differently.
    The working spaces don't matter, it's the document profile(s) that manage the preview. So here is the same grayscale image placed in ID on top and PS on the bottom. I've set my Photoshop info to show the doc profile in the lower left corner. I can see my InDesign's Document CMYK profile in my Proof Setup (the Working CMYK is different and isn't being used). Both profiles are effectively the same Coated FOGRA39 (Black Ink FOGRA in the case of PS).
    But the previews don't match because I have Overprint turned off, so the InDesign preview is Gamma 2.2 or a "screen" media preview.
    If I turn on Overprint preview I get a match because I'm soft proofing for print:

  • How do I change the color of font in a fillable form in Adobe Reader? How can I check if the writer of the document has given permission to edit color and not just add text?

    How do I change the color of font in a fillable form in Adobe Reader? How can I check if the writer of the document has given permission to edit color and not just add text? Please help! I'm technologically challenged.

    Most forms (99% or more) are created for simple text input, where you cannot change anything.
    The creator of the form could allow Rich Text input (which allows you to change font, text size, color, etc.), but frankly I have never seen such a form, and I wouldn't know how they look.  But I'm sure they would show some kind of controls to alter the text appearance.

  • How to print the Terms and Condition page ine the sap-script

    Hi experts,
                             i got the requirement that how to print the Terms and condition page in the script,i have the three pages, having the same main window, in the last of the main window(all three pages)  i have called the hard coded text(i.e so10 text), but when i am displaying the output  data get printed in the first page but i am getting the second page heading on the top of  the terms and condiions page. In all the three pages i  have the same main window, if i  make change in any window i will affect all the other main  windows.  so please suggest me how i need to go.HOW TO GET GRID OF THE TEXT ON THE TOP OF THE SECOND PAGE OF THE TERMS AND CONDITONS.
    like this i have called in the MAIN WINDOW
    /E : LAST ( IN ALL THREE PAGES)
           INCLUDE ZSD_INVOICE_TERMS TEXT OBJECT TEXT LANGUAGE EN.
    IN THE TCODE SO10
    NEW PAGE TERMS.
    1) TERM MS AND CONDITONS  TEXT.................................................
    FIRST->NEXT, NEXT->NEXT,,   TERMS--->TERMS.

    Hi,
    1. Create a new page by Name : LAST
    2. Identify the text element which will be the last element in the form in the debug mode.
    Mostly Ex: SUM, TOTAL, LAST etc.,
    3. the page linking should be
    First --> Next
    Next --> Next
    4. In the Text element identified in the step 3.
    Write the following code
    /: NEW PAGE  LAST
    /: INCLUDE the standard text created for the terms and conditions in SO10
    Check the syntax for the command but the logic will be the same.
    It should resolve your problem.

  • How to print  both normal and bold data in a single line

    Hi ,
    I have requirement wherin the data need to be displayed in a single line.
    FAX:              Z8525_text.
    where FAX needs to be in bold and Z8525_text is a standard text and it shoould not be bold , both of this needs to be displayed in
    a single line.
    Can you let me know how to print  both normal and bold data in a single line one of which is coming fro standard text.
    Regards,
    Senthil

    Hi Senthil,
    If you are using smartforms, have a character format created for BOLD and apply it to the text you want to highlight. The remaining text of the line could be applied with a Character format which is not highlighted.
    Try and revert in case you need further assistance

  • How to print different colors of Strings into JEditorpane?

    How to print different colors of Strings into JEditorpane?
    Can any body give me answer ...

    JEditorPane contain HTML. So write your HTML using the color attribute.
    Start by read the the API description of JEditorPane. you will find a link to the Swing tutorial on "Using Text Components" which has working examples of using a JEditorPane. It also has an example of using a JTextPane where you can dynamically change the attributes of individual pieces of text.

  • Is it possible to change the CATEGORY TITLE font color and/or size of each tile group in start screen, when the tiles are sorted by CATEGORY?

    TIA.

    Q.  Is it possible to change the CATEGORY TITLE font color and/or size of each tile group in start screen, when the tiles are sorted by CATEGORY?
    A.  No
    Carey Frisch

  • How to Increase the Rows and Columns Size of Bex Query in Enterprise Portal  of SAP  7.3

    Dear All,
    Please let me know the process how to Increase the Rows and Columns  Size of Bex Query in Enterprise Portal  of SAP  7.3 .
    Currently I am getting Only  4 columns and 10 rows in One Page .And I am getting 1,2 etc tabs for both row and column. So i want to increase the column length more than 100  and row length more than 10000.
    Please suggest me a suitable solution to over come this issue.
    Please find the Below screen shot.
    Thanks
    Regards,
    Sai

    Dear All,
    Please find the attached screen shot.
    The report be open with 4 or 5 columns and 5 or 6 rows.
    So, please  let me know how to increase the length of the table.
    Do the needful for me to over come this issue.
    Thanks
    Regards,
    Sai.

  • How to print in black and white on a color printer

    I need help printing in black and white. I have a color printer.

    take a look at this discussion
    https://discussions.apple.com/message/20821743#20821743

  • How to print red color in plain paper?

    When printed on glossy papers, red color (in photo or text) looks great.
    When I print on non-photo, plain papers, red color came out brownish.
    I tried on premium ink jet papers, it does not print red but in brown color.
    How can I print red color in plain paper?

    When dealing with printing ink, R=100m+100y+0c+0k. What drives the color toward rust, maroon, and brown is the addition of c to the mix. That may be the result of the diffuse reflection of the uncoated paper surface, its absorb rate, the ink chemistry and – the light source. Since the easiest variable to test is the light source, look at that color using a source weak in blue emission, incandescent light, and watch the red shift. Remember also that the reflected color will never be as bright as paper it is printed on. Each ink film is a filter subtracting light from the paper reflection.  
    Shown above (with a mode change to RGB for the purpose of this display) is its version of 100 each of m+ y  and a patch with the unwanted c

  • HP Photosmart Premium All-in-one c310a - How to print in black and white

    I want to print a color pdf file in b&w on my HP Photosmart Premium All-in-one c310a printer. When I go to "features" -> color options -> grayscale -> in the drop down box, there is only one choice - "high quality". There's no "black ink only" choice as I have seen in forums on similar printers.

    If you have the full feature drivers installed for this printer and there isn't a Black Ink Only option under Print in Grayscale, then this printer lacks the feature.  Typically the Black Ink Only options follows the drivers for some deskjets and most officejets, because of the office environments they are intended for.  Where as Photosmart printers are more aimed at printing photos. 
    -------------How do I give Kudos? | How do I mark a post as Solved? --------------------------------------------------------
    I am not an HP employee.

  • How to print in black and white only?

    Hello,
    I have HP Color Laserjet cp1515n. I downloaded and installed "HP_CP1510_series_full_solution_EMEA3-v4.0" from HP's website for the driver. 
    When printing (in the properties for the printer) there is no option whether to print in black and white only or not. Please help me get that option. And please tell me how I can save toner.
    Thank You
    I have windows xp 

    Hello!
    You can get this accomplished within most word/printing applications or preferences by selecting 'Greyscale' printing or black and white only.
    You can find an article related to this function with more details here:
    http://h10025.www1.hp.com/ewfrf/wc/document?docname=c01514143&tmp_task=useCategory&cc=us&dlc=en&lang...
    Hope this helps!
    Help the community by marking this post as a solution if it solved your issue!.
    If my post helped you in any way, please click the blue KUDOS star under my name! It would mean a great deal.

Maybe you are looking for