Set color to a specific word in text

I hava text in JEditorPane I want to set Color to spacific word in text
thank you

Engy i've been searching.U'll find EXACTLY what u want in the java tutorial ,the folder (uiswing),open the folder (Components) inside it u'll find the file(generaltext.html).there, u'll find a perfect demo with it's 2 classes TextComponentDemo.java & LimitedStyledDocument.java
u can use them.u'll find all u want there..good luck

Similar Messages

  • How to set color of a specific pixel on an artLayer in JS

    I am brand new to PS scripting. I know I can select a 1x1 pixel rectangle and fill it with a specific color, but that seem inefficient.
    Is there a way to quickly and directly set the color of a specified pixel?
    Thanks.

    JTextArea doesn't support this, but if you read the JTextArea API you will find a link to the Swing tutorial on "Using Text Components" that will show you a text component that you can use.

  • Setting color of a specific line?

    okay so in swing is it possible to set a portion of the text in a text field to a different color? Like in my chat program(below) can I make it so all incoming chat(instring) is blue and all outgoing text(string) is red?
    Am I using the wrong text component for changing the color of a line? Should I even be using J text components for this?
    The tutorial often puts tons of different text components in to its examples, and uses odd methods to change the color.
    It seems that I have to use something like setCaretColor, but i am not clear on how to use this in the way I want to use it.
    here is the code:
    import java.io.*;
    import java.net.*;
    import java.io.*;
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.event.*;
    import javax.swing.text.*;
    import javax.swing.JOptionPane;
    import javax.swing.JDialog;
    import javax.swing.JTextField;
    import java.beans.*; //property change stuff
    import java.awt.*;
    import java.awt.event.*;
    public class server extends JFrame implements ActionListener
         JButton recieve;
         String string;
            String instring;
         String aft = " ";
         String bef = " ";
         String allchat=" ";
         JTextField towrite;
         boolean stop = false;
         String name;
         JTextArea chatbox;
         public server(){
                             setSize(490,550);
                             getContentPane().setLayout(null);
                             recieve = new JButton("send message");
                             recieve.setBounds(30,150,150,35);
                             getContentPane().add(recieve);
                                       recieve.addActionListener(this);
                             chatbox = new JTextArea("chat goes here");
                             chatbox.setEditable(false);
                             chatbox.setBounds(10,200,460,270);
                             getContentPane().add(chatbox);
                                            towrite = new JTextField("Write message here");
                             towrite.setBounds(10,475,460,35);
                             getContentPane().add(towrite);
                                            towrite.addActionListener(this);
                             setVisible(true);
                   name = (String)JOptionPane.showInputDialog(null,"Enter your name");
              while(stop==false){
                   try
                   ServerSocket socket = new ServerSocket(4019);
                   Socket insocket =socket.accept();
                   BufferedReader in = new BufferedReader (new InputStreamReader(insocket.getInputStream()));
                   instring = in.readLine();
                   socket.close();
                   bef = instring;
                   if(bef.equals(aft)){}else{
                        allchat=instring+"\n"+allchat;
                        chatbox.setText(allchat);
    catch(Exception e){}
             public void actionPerformed(ActionEvent evt)
            if(evt.getActionCommand().equals("send message"))
    try
    Socket socket = new Socket("67.166.126.246",4020);
    OutputStream out = socket.getOutputStream();
    string=name+": "+towrite.getText();
    byte buffer[] = string.getBytes();
    out.write(buffer);
    socket.close();
    catch(Exception e){}
                   bef = string;
                   if(bef.equals(aft)){}else{
                        allchat=string+"\n"+allchat;
                        chatbox.setText(allchat);
                   aft=bef;
    public static void main(String[] args)
    server s = new server();}}

    Hmmmm im sorry but Im not quite sure I understand how to do this.
    Do you have to know the exact digits at which the text starts and ends?
    or can you, as mentioned just use html tags to set the text color?
    If i were to highlight a line of the text, would that text be highlighted even if its location in the string changed?
    It would seem that tags would be easier but from what I have tried they don't seem to work in editor panes, but the ydo work in buttons
    Im sorry, Im being a bit of a pest, but I have not been doing java for that long, and I do not have a teacher, so all of my questions have to go here.

  • Highlighting or setting color of a certain piece of text in java

    Outpputing 2 java programs to 2 text area..
    want to highlight similar lines of code in both files..
    having probles setting the color of text

    How about looking in the Java API for methods such as setColor and/or setBackgroundColor.

  • Setting color in a specific JTable

    I was wondering if anyone could help me with this problem. I wish to set some cells in the first column only to Yellow. I have done the following;public class customTableCellRenderer extends
    DefaultTableCellRenderer
        JTable table;
    public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column)
    Component cell = super.getTableCellRendererComponent(table,value,isSelected,hasFocus,row,column);//getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
            if(value instanceof String)
                 String s= (String) value;
                 if(value.equals("Monday"))
                    cell.setBackground(Color.YELLOW);
                else
                    cell.setBackground(Color.BLUE);
                 return cell;
    }and my class with the JTable calls the above class:
        public JPanel centre()
            JPanel tablePanel=new JPanel(new BorderLayout());
            Object[] titles = new String[]{"","9.00","10.00","11.00","12.00","13.00","14.00","15.00","16.00","17.00","18.00","19.00"};
            String[] rows = new String[]{"Monday","Tuesday","Wednesday","Thursday","Friday"};
            Object[][] data ={
                        {"Monday","","","","","","","","","","",""},
                         {"Tuesday","","","","","","","","","","",""}};
              DefaultTableModel model=new DefaultTableModel(data,titles); 
              table=new JTable(model);
             String[][] data = new String[rows.length][titles.length];
            JTable timeTable = new JTable(data, titles);         customTableCellRenderer cr=new customTableCellRenderer();
               try
                table.setDefaultRenderer( Class.forName
                   ( "java.lang.Integer" ), cr );
            catch( ClassNotFoundException ex )
                System.exit( 0 );
            table.setDefaultRenderer(Color.class, cr);
            JScrollPane pane = new JScrollPane(table);  
            pane.setSize(new Dimension(500,300));
            pane.setViewportView(table);
            tablePanel.add("Center", pane);
            return tablePanel;
    }it still doesnt set the color in the cells for; Monday, Tuesday, Wednesday, Thursday, Friday.

    Your renderer isn't being used.
    JTable chooses the appropriate renderer based on the value of the getColumnClass(...) method. Since you haven't overridden that method it thinks all data is an Object and uses the Object renderer.
    The following lines accomplish nothing, since you don't store any Integers or Color objects in your table. Every Object is a String.
    table.setDefaultRenderer( Class.forName( "java.lang.Integer" ), cr );
    table.setDefaultRenderer(Color.class, cr);
    If you want you can specifiy a renderer for a specific column. You get the TableColumn from the TableColumnModel and add the renderer directly to the column.
    If all you want to do is color a cell, then another option is to override the prepareRenderer() method. Something like this:
    http://forum.java.sun.com/thread.jspa?forumID=57&threadID=610474

  • Plist strings to UILabel: formatting specific words in the text?

    Developers,
    I have a UILable populated by a plist string. I would like the UILabel to display text, with specific words in bold format.
    I have looked around for a solution to this problem, but I haven't found anything useful on the net.
    Is this possible?
    I have been thinking that this could be done by using a key (e.g. stars around a word *word1*) that identifies particular words within the plist string to be formatted. An if statement could then be used to filter through which words should be formatted, within each string. I'm not sure if this would work or how i would implement it, which is why i turn to you for your experience and advice.
    j
    Message was edited by: james_coleman01

    Hey James!
    james_coleman01 wrote:
    I would like the UILabel to display text, with specific words in bold format.
    Any single instance of UILabel can only have one font, one text color, etc. There's no way to draw one letter or word differently from any other.
    I have been thinking that this could be done by using a key (e.g. stars around a word *word1*) that identifies particular words within the plist string to be formatted. ...
    As always, you're on the right track, James. In fact if you extend your idea to include syntax for italics, underlines, superscripts, etc., then add font family, point size and text color, then add various paragraph styles, you'll be well on your way to inventing what's known as "rich text".
    So the web search keys you needed were "UILabel UITextView rich text". I think the two most common solutions to your requirement are: (1) If the text is static, put the words in separate labels; (2) The recommended, and most general solution: Use UIWebView in place of UILabel.
    No. 2 isn't as kinky as it might seem, even if you've never used HTML (the most widely known example of rich text). Here's a short blog that's probably enough to get you going: [Display Rich Text Using a UIWebView|http://iphoneincubator.com/blog/windows-views/display-rich-text-using -a-uiwebview]. The responses on that page include some good tips too.
    \- Ray

  • How to set to bold a single word in the text box?

    How can I set to bold a single word in the text box? When I try, it puts the whole text bold.

    you should do this by HTML way
    like this :
    sym.$("your text box Name").html("Hello i'm <strong>Bold</strong> one")
    Zaxist

  • Change the background color of a particular word without changing the background color of the rest of the text in a textbox

    Hello,
    I'm designing my own website and want to know how to change the background color of a particular word without changing the background color of the rest of the text in a textbox. If i can't do this, how can I create a Table, similar to Excel with iWeb?
    Thank you very much!
    Roger.

    If i can't do this, how can I create a Table, similar to Excel with iWeb?
    Read this :
         Create and add a TABLE in iWeb »
         More about a TABLE in iWeb »
         Sample 1
         Sample 2

  • How do you set the font color for a specific entire row inside a JTable?

    How do you set the font color for a specific entire row inside a JTable?
    I want to change the font color for only a couple of rows inside a JTable.
    I've seen some ways to possibly do this with an individual cell.
    Clarification on changing the font color in an individual cell would be helpful too if
    there is no easy way to do this for a row.

    hai,
    Try out with this piece of code.Create your table and assign the renderer to each column in the table.
    CellColorRenderer m_CellColorRenderer = new CellColorRenderer();
    for(int i=0;i<your_JTable.getColumnCount();i++)
    your_JTable.getColumnModel().getColumn(i).setCellRenderer(m_CellColorRenderer);
    class CellColorRenderer extends JLabel implements TableCellRenderer
    CellColorRenderer()     
    setOpaque(true);     
    setHorizontalAlignment(LEFT);
    setVerticalAlignment(CENTER);
    setBackground(Color.white);
    setForeground(Color.black);
    protected void setValue(Object value)
         setText((value == null) ? "" : value.toString());
    public Component getTableCellRendererComponent(JTable table,Object value,boolean isSelected, boolean hasFocus, int row,int column)
         if(isSelected == true)
              setForeground(Color.red);
         else
              setForeground(Color.black);
         setValue(value);
         return this;
    regards,
    bala

  • Program to read only specific words in each Line in a text file

    Hi
    I have a question
    I need to write a program where the program must read only specific words in each line
    I will give you an example...
    PSAPPSRV.21201      1-42 13.35.54 238.360 Cur#1.HDEV RC=0 Dur=0.000 COM Stmt=SELECT VERSION FROM PSVERSION WHERE OBJECTTYPENAME = 'SYS'
    PSAPPSRV.21201      1-43 13.35.54 0.040 Cur#2.HDEV RC=0 Dur=0.000 COM Stmt=SELECT STYLESHEETNAME FROM PSOPTIONS
    These are two lines in my text file...now I need to read only the SQL statements present that is both SELECT statements.. Can you please suggest a method.......

    My first reaction to the question is why would you want such thing, but may be I am unknown :)
    Assuming you have the text as string, I mean
    String str = "PSAPPSRV.21201 1-42 13.35.54 238.360 Cur#1.HDEV RC=0 Dur=0.000 COM Stmt=SELECT VERSION FROM PSVERSION WHERE OBJECTTYPENAME = \'SYS\'";you can obtain the sql statement using substring method like
    String result = str.substring(str.indexOf("SELECT")); Again I assume there is no word SELECT preceding and the word SELECT is all caps.

  • When using spotlight search on my 5s it will not show past text messages that haven't even been deleted even if I type a specific word that I know is in a message I want to search for. I have message search turned on in the spotlight settings.

    When using spotlight search my phone will not show all text messages with a common word even though I have not deleted any messages from my phone and I have the message search turned on in settings under spotlight search. The search only shows the messages that are recent within the past day or so. Why won't it show the other messages when I search for them even using a specific word that I know was in the message I'm searching for.

    Hello ChiomaM,
    It sounds like you are not getting notifications for new text messages that are coming in, and you must manually check the app. I recommend checking the Notification settings to see if they are configured correctly:
    iOS: Understanding notifications
    http://support.apple.com/kb/ht3576
    iOS apps can provide three types of notifications:
    Sounds: An audible alert plays.
    Alerts/Banners: An alert or banner appears on the screen.
    Badges: An image or number appears on the application icon.
    You can view which apps provide notifications and adjust notification settings using Settings > Notification Center. For additional information, refer to the user guide for your device.
    Thank you for using Apple Support Communities.
    Regards,
    Sterling

  • Add xml tag to specific words in a text frame

    Dear all,
    I'm pretty sure this can't be too much of a hassle, but after hours of experimenting, searching and reading I can't seem to look at it from the right angle. I'm trying to find a way to search for a specific word ('Figure', in my case) in a given text frame, and add a corresponding XML tag to it automatically. I've found plenty of information on how to apply it to a page item as a whole, but from there no approach seems to work. Seeing as I'm fairly new to InDesign scripting, any nudge in the right direction would be an immense help.
    Kind regards and thanks in advance,
    Julian

    Hi Julian,
    Is this you asking?
    var doc = app.activeDocument;
    app.findTextPreferences.findWhat = "figure";
    var found = doc.findText();
    for(var i =0;i<found.length;i++)
            doc.xmlElements[0].xmlElements.add({markupTag:"figure", xmlContent:found[i]});
    Regards,
    Chinna

  • Find word in text file and count specific words

    now I'll try to explain what I need to do. I have file.txt file, It looks like:
    John //first line - name
    One
    Three
    Four
    Peter //first line - name
    Two
    Three
    Elisa //first line - name
    One
    Three
    Albert //first line - name
    One
    Three
    Four
    Nicole //first line - name
    Two
    FourSo I have program's code:
    public class Testing {
            public static void main(String args[]) throws Exception {
                Scanner input = new Scanner(System.in);
                System.out.println("Select word from list:");
                System.out.println();
                try {
                    FileReader fr = new FileReader("src/lt/kvk/i3_2/test/List.txt"); // this is list of words, everything all right here
                    BufferedReader br = new BufferedReader(fr);
                    String s;
                    while((s = br.readLine()) != null) {
                        System.out.println(s);
                    fr.close();
                    String stilius = input.nextLine();   // eneter word which I want to count in File.txt
                    BufferedReader bf = new BufferedReader(new FileReader("src/lt/kvk/i3_2/test/File.txt")); // from this file I need to count word which I entered before
                    int counter = 0;               
                    String line;
                    System.out.println("Looking for information");
                    while (( line = bf.readLine()) != null){
                        int indexfound = line.indexOf(stilius);
                        if (indexfound > -1) {
                             counter++;
                    if (counter > 0) {
                        System.out.println("Word are repeated "+ counter + "times");}
                        else {
                        System.out.println("Error...");
                    bf.close();
                catch (IOException e) {
                    System.out.println("Error:" + e.toString());
            }This program counting specific word (entered by keyboard) in file.txt.
    I need to make this program: for ex.: if I enter word: One It must show:
    Word One repeated 3 times by John, Elisa, AlbertAll what I need to elect by who this word repeated. But I don't know really how to make It, maybe LinkedList or I dont know, someone could help me?
    Thank you very much.

    966676 wrote:
    All what I need to elect by who this word repeated. But I don't know really how to make It, maybe LinkedListYou should choose the simplest type fullfilling your needs. In this case I'd go for <tt>HashSet</tt> or <tt>ArrayList</tt>.
    or I dont know, someone could help me?You need to introduce a variable to store the actual name which must be resetted if an empty line is found and then gets assigned the verry next word in the file.
    bye
    TPD

  • How to highlight specific words in the Reader

    Hi!
    I am new to the Acrobat SDK and could need some guidance on how to solve the following problem:
    I need a plug-in that is able to highlight specific words in a pdf file (e.g. by underlining it or changing the background color) and offers a context menu with futher actions when the user clicks on a highlighted word. The first step would be searching the text to find the word that should be marked. I think that should not be that hard but how can I highlight specific words? I first thought of annotations but I need it in the Reader and I should not change the pdf file itself (just the view of it).
    The idea is similar to the skype plug-in for Firefox or IE. The skype plug-in highlights phone numbers. We need to highlight specific words.
    Thanks for every hint on how to achieve this!
    Fabian

    >The documentation says that AVPageViewHilightText is supposed to use >the current color set with AVPageViewSetColor - so it should work. >What version of Acrobat are you working with?
    Yes that how understood the documentation too. I tried the following:
    //Define red
    red.space = PDDeviceRGB;
    red.value[0] = ASInt32ToFixed(1);
    red.value[1] = 0;
    red.value[2] = 0;
    // highlight
    AVPageViewSetColor(pageView, &red);
    PDTextSelect pdTextSelect = PDDocCreateTextSelect(pdDoc, pageNum, &bbox);
    AVPageViewHighlightText(pageView, pdTextSelect);
    I am using Acrobat 7.0.9.
    >Drawing an image would be done with AVPageViewDrawCosObj
    >- which means you'll need to bring the image in as a PDF
    > object and then render it.
    Oh I should have seen that. Thanks for the hint!!
    >Interesting, there should be a way to get transparency,
    > but I am not seeing it at the moment.
    As far as I understood it, it is possible to set the color to transparent but thats not what I am looking for. I would like to have a way of changing the alpha channel of the color.
    Thanks!
    Fabian

  • Can't open document using Word or Text Edit

    I couldn't find a specific topic so I'm posting this here. I just got a new white macbook and transferred some word documents to it. I was out of town and realized I'd forgotten to load the Word program, so I opened a couple of documents using Text Edit and saved them as new documents. One document opened without issue, but the other document won't open with either Text Edit or MS Word 2004. When I try to open it in Word the message states it cannot be opened and may or may not be a valid word document. When I try to open in TextEdit the message states that the document is not in the right format. Please help -- I really don't want to have to re-create the document as it is about 12 pages!
    Thanks, Sandy

    There are 2 unusual options in File, Open in the Windows version of Word (sorry, I'm on a Mac without Word). One is something like Recover Text From Any Format, and the other is Open and Repair. One I think is on a drop down menu in the Open screen. I'm not sure if these are available on the Mac version, but it's worth a try! Also: do you have all the proper converters set up? I have Word 2004 for Mac running on one machine, a legal copy, and I was able to do updates and even get a free conversion program that actually backward converts Word 2007 for Windows and Word 2008 for Mac files down to Word for Mac 2004. It's worked quite will. I support Word on Macs and Windows at work and have used that conversion utility to great advantage when we had users call with Word docs that wouldn't open. Good luck!

Maybe you are looking for

  • GO Button Hide

    Hi Experts, Is ther any options on whether a 'GO' button can be removed from the Dashboard prompt(drop down). When the user selects the prompts the action whatever happens when you click 'Go' button should happen. Check if we can hide the Go button a

  • Cannot connect to my wi fi at home IPOD 4th generation OS 6

    Picked up a used (3mths only or so they say) IPOD last night for my son and cannot connect to our home WI FI   - i have followed all the manual and resets....any suggestions?

  • Accounting No not Created For Sales Orders when Processed thru Credit cards

    Hi Experts, I was able to successfully post FI document through Billing document in SD. The Problem is encountered when a Sales Order is created for Credit Card customers. When the sales order is created the credit card information we are prompted wi

  • Is it possible to import a pdf instead of a jpg to put in the base "photo layer?"

    Is it possible to import a pdf instead of a jpg to put in the base "photo layer?" I start with a pdf document convert it to a jpg      mark it up in ideas      then finish up with a marked up  jpg document      then reconvert it back to a pdf I can o

  • Ken burns effect won't die

    I want to globally turn off the Ken Burns effect for my 722 slides in my iMove slide show. I have clicked on Project Properties, Timing, Fit in Frame, apply to all. But still it won't go away. I really don't want to do one at a time. What else can I