How can I add highlighting to my simple text editor?

Hi ...I wrote a simple text editor ..but I want to add Sysntax highlihting to my editor ...ilke I will enter some words in sourse code (new..import.. ext ) and when I write in text those words I want to see whit a different collor ..how can I do this? here is source codes for my text editor..and I want your help
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.text.*;
import javax.swing.plaf.ComponentUI;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.*;
import java.util.regex.*;
public class JText extends JFrame{
     private JTextArea textarea ;
     private JFileChooser fileChooser = new JFileChooser();
private Action open =new OpenAction() ;
private Action save = new SaveAction();
private Action exit = new ExitAction();
public static void main(String args[])
          JText pencere= new JText();
          pencere.setBackground(Color.lightGray);
          pencere.setSize(400,300);
          pencere.setVisible(true);
     //Text Area
     public JText(){
     textarea = new JTextArea(15,90) ;
     JScrollPane scroll = new JScrollPane(textarea);
     JPanel content = new JPanel();
content.setLayout(new BorderLayout());
content.add(scroll, BorderLayout.CENTER);
     //Menu Bar
JMenuBar menu=new JMenuBar();
JMenu file=menu.add(new JMenu("FILE"));
file.setMnemonic('F');
file.add(open);
file.add(save);
file.addSeparator();
file.add(exit);
setContentPane(content);
setJMenuBar(menu);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setTitle("Project");
pack();
setLocationRelativeTo(null);
setVisible(true);
     class OpenAction extends AbstractAction {
     //============================================= constructor
     public OpenAction() {
     super("Open...");
     putValue(MNEMONIC_KEY, new Integer('O'));
     //========================================= actionPerformed
     public void actionPerformed(ActionEvent e) {
     int retval = fileChooser.showOpenDialog(JText.this);
     if (retval == JFileChooser.APPROVE_OPTION) {
     File f = fileChooser.getSelectedFile();
     try {
     FileReader reader = new FileReader(f);
     textarea.read(reader, ""); // Use TextComponent read
     } catch (IOException ioex) {
     System.out.println(e);
     System.exit(1);
          class SaveAction extends AbstractAction {
          //============================================= constructor
          SaveAction() {
          super("Save...");
          putValue(MNEMONIC_KEY, new Integer('S'));
          //========================================= actionPerformed
          public void actionPerformed(ActionEvent e) {
          int retval = fileChooser.showSaveDialog(JText.this);
          if (retval == JFileChooser.APPROVE_OPTION) {
          File f = fileChooser.getSelectedFile();
          try {
          FileWriter writer = new FileWriter(f);
          textarea.write(writer); // Use TextComponent write
          } catch (IOException ioex) {
          JOptionPane.showMessageDialog(JText.this, ioex);
          System.exit(1);
               class ExitAction extends AbstractAction {
               //============================================= constructor
               public ExitAction() {
               super("Exit");
               putValue(MNEMONIC_KEY, new Integer('X'));
               //========================================= actionPerformed
               public void actionPerformed(ActionEvent e) {
               System.exit(0);
}

i looked it ...it is the one which i want to do ..But i want to use my window which i gave above ..But i cant mix them ..:( this codes for highlighting.... is any body can add this codes and my codes which i gave above connect together? pleaseeeee... :))
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.text.*;
import java.util.*;
import java.awt.*;
import java.awt.event.*;
public class SyntaxTest extends DefaultStyledDocument
Element rootElement;
String wordSeparators = ",:;.()[]{}+-/*%=!&|~^@? ";
Vector keywords = new Vector();;
SimpleAttributeSet keyword;
public SyntaxTest()
rootElement= this.getDefaultRootElement();
keyword = new SimpleAttributeSet();
StyleConstants.setForeground(keyword, Color.blue);
keywords.add( "abstract" );
keywords.add( "boolean" );
keywords.add( "break" );
keywords.add( "byte" );
keywords.add( "case" );
keywords.add( "catch" );
keywords.add( "char" );
keywords.add( "class" );
keywords.add( "continue" );
keywords.add( "default" );
keywords.add( "do" );
keywords.add( "double" );
keywords.add( "else" );
keywords.add( "extends" );
keywords.add( "false" );
keywords.add( "final" );
keywords.add( "finally" );
keywords.add( "float" );
keywords.add( "for" );
keywords.add( "if" );
keywords.add( "implements" );
keywords.add( "import" );
keywords.add( "instanceof" );
keywords.add( "int" );
keywords.add( "interface" );
keywords.add( "long" );
keywords.add( "native" );
keywords.add( "new" );
keywords.add( "null" );
keywords.add( "package" );
keywords.add( "private" );
keywords.add( "protected" );
keywords.add( "public" );
keywords.add( "return" );
keywords.add( "short" );
keywords.add( "static" );
keywords.add( "super" );
keywords.add( "switch" );
keywords.add( "synchronized" );
keywords.add( "this" );
keywords.add( "throw" );
keywords.add( "throws" );
keywords.add( "true" );
keywords.add( "try" );
keywords.add( "void" );
keywords.add( "volatile" );
keywords.add( "while" );
public void insertString(int offset, String str, AttributeSet a) throws BadLocationException
super.insertString(offset, str, a);
int startOfLine = rootElement.getElement(rootElement.getElementIndex(offset)).getStartOffset();
int endOfLine = rootElement.getElement(rootElement.getElementIndex(offset+str.length())).getEndOffset() -1;
//highlight the changed line
highlightKeyword(this.getText(0,this.getLength()), startOfLine, endOfLine);
public void remove(int offset, int length) throws BadLocationException
super.remove(offset, length);
int startOfLine = rootElement.getElement(rootElement.getElementIndex(offset)).getStartOffset();
int endOfLine = rootElement.getElement(rootElement.getElementIndex(offset+length)).getEndOffset() -1;
//highlight the changed line
highlightKeyword(this.getText(0,this.getLength()), startOfLine, endOfLine);
public void highlightKeyword(String content,int startOffset, int endOffset)
char character;
int tokenEnd;
while (startOffset < endOffset)
tokenEnd = startOffset;
//find next wordSeparator
while(tokenEnd < endOffset)
character = content.charAt(tokenEnd);
if(wordSeparators.indexOf(character) > -1)
break;
else
tokenEnd++;
//check for keyword
String token = content.substring(startOffset,tokenEnd).trim();
if(keywords.contains(token))
this.setCharacterAttributes(startOffset, token.length(), keyword, true);
startOffset = tokenEnd+1;
public static void main(String[] args)
JFrame f = new JFrame();
JTextPane pane = new JTextPane(new SyntaxTest());
JScrollPane scrollPane = new JScrollPane(pane);
f.setContentPane(scrollPane);
f.setSize(600,400);
f.setVisible(true);
}

Similar Messages

  • How can I add multiple contacts to a text message on a droid bionic

    How can I add multiple contacts to a text message on a droid bionic?

    DH
    I was thinking that if he wanted to create multiple keyframes he might be creating a repeated effect rather than manipulating values that are shot specific - like creating an oscillation or some repeated step effect.  If he was creating keyframes specific to his content he'd probably not look for a way to do it "quickly" since each keyframe would require manipulation of specific values. 
    So my thought was to generate the series of keyframes on a dummy clip created for this specific purpose, copy the clip, paste attributes (maybe turn off "Scale Attribute Times") and add bunches of keyframes at once. 
    Still, you're right, it's tough to divine the intent of someone very new to FCP.  His question could be based on a misunderstanding about the use of keyframes.
    P

  • How can I add a new message(custom text message) to the holiday approval em

    How can I add a new message(custom text message) to the holiday approval email-notification sent to the manager?
    TIA

    The answer is 'not very easily', unless the information you want to display is the employee's leave balances. In 12.1.3 Oracle have delivered functionality that allows you to include the leave balances in the approval notifications out-the-box, ie, without customization.
    For any other information you're probably going to have to customize the standard delivered HRSSA workflow. Within this workflow, the Leave of Absence functionality uses the Notify Approver (Embedded) (HR_APPROVER_NTF) notification. The body of this notification is set to the Notify Approver (Embedded) (HR_NTF_EMBEDDED_REGION) attribute. This in turn defaults to:
    JSP:/OA_HTML/OA.jsp?OAFunc=-&HR_EMBEDDED_REGION-&NtfId=-&#NID-
    So essentially you can change the HR_APPROVER_NTF notification. The problem with changing this notification is that it's generic - it's used for all SSHR functions and not just Leave of Absence. That means you have to make other, more substantial, customizations to the workflow to ensure the changes you make only applies to LOA.
    The other option is to personalize the review page (ie, the region referenced in &HR_EMBEDDED_REGION) to include whatever messages you want. But that means they'll appear on the Review page and all LOA approval notifications and that might not be what you want.
    It's usually better to live with what Oracle deliver and find an alternative solution! What's the content of the message you want to include?

  • How can I add an information (including pic, text and button) area in the menu?

    The picture below is captured from on video in Adobe Muse official website. How can I add an area just like the picture shows? I mean the three sleeping bags, texts below and the learn more button.
    Thank you.
    (from http://tv.adobe.com/watch/creative-cloud-for-design/adobe-muse-november-2013-hide-menu-nav igation-on-rollout/)

    This tutorial <http://helpx.adobe.com/muse/tutorials/widgets.html> has a section titled "Hiding Composition widgets on rollout to create submenus" which covers how to use a Composition widget for this purpose.

  • How can I add an Image to a text

    Hello
    I want to add a image into the block of text as in the
    following link:
    (you can see a image in yellow color=50 years is aligned with
    the text)
    http://www.gammonconstruction.com/hk/eng/home/default.html
    How can I do this in DW-2004? do i have to use CSS here?

    Yes use css
    .imgright {float: right; padding: 10px;}
    or to the other side
    .imgleft {float: left; padding: 10px;}
    changing the padding to suit.
    and then apply the class to your image. eg here:
    http://www.dreamweaverresources.com/tutorials/images_text.htm
    Nadia
    Adobe® Community Expert : Dreamweaver
    CSS Templates |Tutorials |SEO Articles
    http://www.DreamweaverResources.com
    ~ Customisation Service Available ~
    http://www.csstemplates.com.au
    ~ Forum Posting Guidelines ~
    http://www.adobe.com/support/forums/guidelines.html
    "ldfinhk" <[email protected]> wrote in
    message
    news:evt8t6$jed$[email protected]..
    > Hello
    >
    > I want to add a image into the block of text as in the
    following link:
    >
    > (you can see a image in yellow color=50 years is aligned
    with the text)
    >
    >
    http://www.gammonconstruction.com/hk/eng/home/default.html
    >
    > How can I do this in DW-2004? do i have to use CSS here?
    >
    >

  • How can I add a third line of text to a title?

    I am making a music video for my highschool students to teach about recycling and I want to add a title to the bottom with the song title, the name of the ficticious band and the ficticious record label.
    I have tried to add the third line of text, but I can't seem to figure out how. the title needs to be superimposed on the actual video, so adding in a clip created in photoshop or something won't work. Think about the titles you'd see at the begginning and end of a music video, and that's pretty much what I am going for.
    Any suggestions?
    Thanks
    PS this is my first post and my first mac, so be gentle

    Bubbalouie123754 wrote:
    ....  the title needs to be superimposed on the actual video, so adding in a clip created in photoshop or something won't work. ....
    It does.
    The whole trick is to use a transparent background and using .png as file-format for your superimposed graphics:
    illustrated advice on my site
    https://sites.google.com/site/karstenschluter/imovie09tricks
    'Creating new titles'
    (advice was for vers09, does work in vers11)
    … and Welcome, Bubbalouie, to the ASC ...

  • How can I add a title and ALT text to a JPEG image in Elements 11 for MAC?

    Does anyone know if there is an easy way I can add a title and ALT text to a JPEG image in Elements 11 for MAC?
    Very grateful for any help here.

    Hello
    The Arrange menu is your friend.
    You may select the arrow then "Bring to Front".
    Yvan KOENIG (from FRANCE vendredi 19 septembre 2008 17:49:50)

  • How can I add a header to a text file without mapping? [Using only ID]

    Hi Experts,
    I am doing a scenario in which I want to add a dynamic header to a text file, due to the complications related to the structure, I dont want to create a message type, data type etc so I cant use mapping.
    I want to do all the manipuations in Integration Directory itself.
    Can you all please help me out in this?
    Thanks in advance
    Thomas

    Hi  Experts,
    I am new to XI, so only elaborate answers would help me
    This is the specific requirement i want;
    There is a 'source text file' which is a collection of 1000+ records, I want to make a 'target file' which is a combination of 2 fields, one field will be the dynamically generated name [for the target file] and the other field will be the whole 'source file' content.
    From the last response for my question, I understand the dynamic file generation part can be done using java mapping.
    Is there anyway by which I can get in the whole content of the source file into a field in the target file?
    Thanks in Advance
    Thomas

  • How can I add an appoggiatura using the score editor?

    I'm using Logic Pro X to write an ensemble piece and I need to add an appoggiatura, how do I do it?

    Hi
    I'm not sure what your issue is: add extra notes, convert them to Independent Grace notes, and adjust the positions using the Layout tool as needed.
    CCT

  • How can I add a whole paragraph of text to an IPad Numbers row?

    I can add the text just fine, and the text wraps to the next line as I type it, but when I'm done only one row of text appears.  If I change the row height, it creates a nice high row, but again only the first line appears at the bottom of the row.

    Under the Format button ( the paintbrush) at the top of the screen turn on "Wrap text in cell".

  • How can i add a file name(the text of the file name) as a child node to existing node in a treeView1 ?

    bool exists = false;
    TreeNode newNodeParsed = null;
    TreeNode rootNode = treeViewMS1.Nodes[0];
    TreeNode nextNode = rootNode;
    string f = Path.GetFileName(txtUploadFile.Text);
    TreeNode subnode = new TreeNode(txtDir.Text);
    TreeNode filename = new TreeNode(f);
    if (!txtDir.Text.Contains("/"))
    foreach (TreeNode node in rootNode.Nodes)
    if (node.Text == txtDir.Text)
    exists = true;
    break;
    if (exists == true)
    subnode.Nodes.Add(f);
    else
    rootNode.Nodes.Add(subnode);
    subnode.Nodes.Add(f);
    The rootNode is the root directory in the treeView1
    subnode is a node inside the root. For example the subnode name is manuelisback
    I'm checking if the subnode exist i want to add the file for example (lightning1.jpg) to be under subnode.
    If the subnode is not existing add the subnode to the root and then add the file name lightning1.jpg under the subnode.
    But the file name is never added under the subnode:
    I added manualy the lightning1.jpg under test.
    But the lightning1.jpg also should be added to be under manuelisback. There should be two lightning1.jpg here.
    One under manuelisback and one under test. The one under test i added manualy from my ftp server.
    But the one i want to be under manuelisback i'm trying to add from my program and it dosen't add it to there.
    And when i'm using a breakpoint i see on subnode the text manuelisback and i see on f the text lightning1.jpg

    If I understand your question correctly, you might want to try changing:
    if (!txtDir.Text.Contains("/"))
    foreach (TreeNode node in rootNode.Nodes)
    if (node.Text == txtDir.Text)
    exists = true;
    break;
    if (exists == true)
    subnode.Nodes.Add(f);
    else
    rootNode.Nodes.Add(subnode);
    subnode.Nodes.Add(f);
    to something like:
    if (!txtDir.Text.Contains("/"))
    foreach (TreeNode node in rootNode.Nodes)
    if (node.Text == txtDir.Text)
    subnode = node;
    exists = true;
    break;
    if (exists == true)
    subnode.Nodes.Add(f);
    else
    rootNode.Nodes.Add(subnode);
    subnode.Nodes.Add(f);
    rootNode.Nodes.Add(f);
    It would be greatly appreciated if you would mark any helpful entries as helpful and if the entry answers your question, please mark it with the Answer link.

  • How do you add a third party web text editor to Muse?

    I'm recreating a site and I need a way to store publications on one of the pages of the site. It's something that is updated weekly so I need it to have an archive feature but I really no idea how this can be done. Here's an example:
    I downloaded this thing called CKEditor but have no clue how to use it... Any help would be great.

    Hi Ethan,
    As you can see from my Word document, I am a little light on the proper terminology.  That's because LVLM comes with inadequate documentation.
    I have already followed your recommended protocol for installing a 3rd party sensor (in fact, its the protocol recommended by Mindsensors) with the application set in the Remote Mode (.lvrbt), and it does create a sub-palette with all the Mindsensors functions on it.  But when I drag the Mindsensors icon to the Block Diagram and select "Distance Sensor," the Distance Sensor (an IR sensor) doesn't work (even though the Mindsensor's Distance Sensor does work with NXT-G, RobotC and LVLM under other circumstances (see below)).
    If I repeat the above process with the application set in the Direct Mode (.vi), I also get the sub-palette with all the Mindsensors functions on it.  When I drag the Mindsensors icon to the Block Diagram and select "Distance Sensor," the Distance Sensor does work.
    What I need for my mapping application is for the Distance Sensor to work in the Remote Mode.  I called NI tech support and the first engineer told me to simple drag the Mindsensors Functions (.vi) onto the Block Diagram.  I did this, but when I selected the Distance Sensor, the icon appeared, but the sensor did not work.  Since I have no idea what's under the hood of the vi or a function, I assumed that simply dragging the vi/function onto the desktop didn't install the vi/function properly.  I went back to the Applications Engineer, and he confessed that he did not understand the LVLM product.
    My frustration is being punted to new people, none of whom so far (other than you, of course) understand LVLM.

  • How can I add KeyListener to JTable editor

    Hi, I want to know how can I add a KeyListener to a JTable editor?
    I want to capture the event when any of the cell in the jtable has a key typed.

    If your goal is to check the entered value, it's more elegant to do this in overriding
    DefaultCellEditor#stopCellEditing and return false when the value is not correct.
    Example from a DateEditor:
            @Override public boolean stopCellEditing() {
                String value = ((JTextField)getComponent()).getText();
                if(!value.equals("")) {
                    try {
                        formatterE.parse(value);
                    } catch (ParseException e) {
                        ((JComponent)getComponent()).setBorder(new LineBorder(Color.red));
                        return false;
                return super.stopCellEditing();
            }

  • HT1800 How can I add a Epson Stylus SX445w to my mac Book Pro this is the second one I've tried and failing miserably...it should be so simple...spoken to the help line at Epson and they say it's down to Apple !! Somebody please help me

    How can I add a Epson Stylus SX445w to my Mac Book Pro
    This is the second one I've tried and failing miserably...it should be so simple...I've installed poken to the help line at Epson and they say it's down to Apple !! Somebody please help me

    Yes I did everything that I was instructed to do!
    Cheers
    Joyce

  • How to let add external apps for simple users?

    How to let add external apps for simple users? Simple users don't have login server administer rights, so how can they add external apps for their use?

    ...Edit External applications portlet sais:
    Error: An unexpected error occurred: User-Defined Exception (WWC-43000)
    :(((

Maybe you are looking for

  • Displaying the sizes of every table in a database

    Hello All, I need to get the table sizes for each and every table in a database. I would have checked it manually but there are many number of tables. I am using SQL Server 2008 R2. Thanks and Regards, Readers please vote for my posts if the question

  • Discoverer Report Ownership and Exports

    We are currently upgrading to R12 from 11.5.10 and I'm looking to migrate discoverer with it. The environment and set up of disco has been completed however there are a few issues around migrating the existing reports and EUL I'm not sure about. I wo

  • Watching cable tv on the macbook

    I see plenty of forums about connecting the macbook to your tv, but I'd like to use the macbook AS a tv. My buddy, who is a PC guy, has his cable (tv connection) plugged into his pc and can watch the cable channels on his monitor. The instructions I

  • FlashPaper Links And Office 2007

    Is anyone else having issues with links working in Powerpoint 2007 and converting them to Flash and PDF files in Flashpaper? Since going to Office 2007 I cannot make the links work in Flashpaper now, and they always worked fine in Office 2003... Than

  • Error calculatio​n with LabView

    I am just courious, maybe someone did such error estimation with LabView, and can show me a better approach. Scenario: I have the following function with one variable (x), K is a constant: y = ( -1/2*K + SQRT( 1/4*K^2 - (4*K - K^2)*(x^2 - x) ) ) / (2