Highlighter in JEditorPane

Hi,
In the Java Look and Feel Design guidelines(http://java.sun.com/products/jlf/at/book/index.html)
I saw a guideline for a Wizard.
I tried to build it, but I have a problem.
How to create a Highlighter ??
Does anyone has some code ???
Thank you,
Evert

Hi,
In the Java Look and Feel Design guidelines(http://java.sun.com/products/jlf/at/book/index.html)
I saw a guideline for a Wizard.
I tried to build it, but I have a problem.
How to create a Highlighter ??
Does anyone has some code ???
Thank you,
Evert

Similar Messages

  • Different Colored Highlights in JEditorPane

    Hello there,
    I have a question regarding different highlights. I have multiple highlights in different color. Is there any way I can selectively remove highlights.
    Meaning say, I have two highlights one with red colored painter and another with green colored painter. Then is there a way, wherein I can remove highlight for the highlight in green color while retaining the highlight in red color.
    I did something like this
    Highlighter.Highlight[] selections= edit.getHighlighter().getHighlights();
    for (int i=0; i<selections.length; i++) {
    Highlighter.HighlightPainter painter= selections.getPainter();
    //DefaultHighlighter.DefaultHighlightPainter painter
    //Color clr = painter.getColor();
    But the getColor() method is there only in DefaultHighlighter.DefaultHighlightPainter and not in Highlighter.HighlightPainter.
    May be I am missing some small thing.
    Thanks a lot for your help.

    But the getColor() method is there only in DefaultHighlighter.DefaultHighlightPainter and not in Highlighter.HighlightPainter.So cast the Highlighter... to a DefaultHighlighter...
    Highlighter.Highlight[] highlights =      textPane.getHighlighter().getHighlights();
    for (int i = 0; i < highlights.length; i++)
         Highlighter.Highlight h = highlights;
         DefaultHighlighter.DefaultHighlightPainter thePainter = (DefaultHighlighter.DefaultHighlightPainter)h.getPainter();
         System.out.println( thePainter.getColor() );

  • How to make keyword highlight in JEditorPane

    I want to write a simple editor which can make keywords syntax highlight.Then I download an example from http://java.sun.com/products/jfc/tsc/articles/text/editor_kit/index.html .But when I run this example I find it has two problems.(This example's name is JavaEditorKit)
    when I insert a " in the editor or I insert a /* from the begin of editor, the example while throw several exceptions.
    java.lang.NullPointerException
    at sun.tool.java...............
    at sun.tool.java..................
    If somebody meet this problem,please help me or email to me ([email protected])

    http://www.japisoft.com/syntaxcolor/
    I tried downloading your app but it didn't work. I went to your samples directory:
    a) the "modeler" seemed to work
    b) the "simple" program started but there was only a "?" in the combobox so no highlighting occurred when I loaded a file
    c) the "file-sample" hasn't been compiled.

  • Effiecient method to get number of lines in a JEditorPane

    My Computer Science class has a major grade project to complete by Dec. 15. For my project I've decided to make a tabbed Java IDE with save, open, compile, run, and some font options. Due to the need to make Java use the command prompt to compile and run, it will be Windows specific.
    Now, next to my JEditorPane I want to put a JPanel with a GridLayout full of JLabels that will hold the line numbers. I'm having a small problem getting the precise number of lines though. Due to the nature of JEditorPane, I can't just count the number of newline characters in the JEditorPane. I've tried to use a Scanner to go through the text and find all instances of the string "<p style=\"margin-top: 0\">" but because the JEditorPane doesn't make a new <p> tag until text is entered into a new line, this only works some of the time.
    Does anyone know of a way I can effectively and efficiently find the number of lines in the JEditorPane at any given time?
    Message was edited by:
    TheGuy@YourWindow

    Swing related questions should be posted in the Swing forum.
    Normally for a text editor you would use a JTextArea for simple text or a JTextPane if you plan on doing syntax highlighting. JEditorPane is typically used to display HTML files.
    If you search the Swing forum using "utextcomponent" you will find my class that has methods that might be handy for what you want.

  • JEditorPane & /p -Tag

    Hi,
    I'm writing a tool that's displaying & printing HTML-text. But there's one problem:
    I get a different line-spacing inside the paragraph than between the last line of the paragraph and the line before.
    Any help? please ...?
    thx, Florian

    Swing related questions should be posted in the Swing forum.
    Normally for a text editor you would use a JTextArea for simple text or a JTextPane if you plan on doing syntax highlighting. JEditorPane is typically used to display HTML files.
    If you search the Swing forum using "utextcomponent" you will find my class that has methods that might be handy for what you want.

  • Highlighting text in JEditorPane using HTMLEditorPane

    I am using JEditorPane extending HTMLEditorkit. In the HTMLEditorkit when we use the span tag for highlighting the text of a line, it is just not showing it. It starts the color and ends it there and then. It looks like a small dot and doesnot spans the whole line.
    Is this a bug or something in JAVA 1.3.1. If anyone of you knows how to do it please let me know.
    I need it for a project which has a deadline.
    Thanks.

    JEditorPane is not rendering and HTMLDocument.HTMLReader is not reading the SPAN tag. In other words, the SPAN tag is not supported in Java. You can still use it by overriding the mentioned classes. My application SimplyHTML gives an example of how this can be done. Please visit http://www.lightdev.com/dev/sh.htm
    Ulrich

  • How to load a text file int JEditorPane and highlight some words (Urgent !)

    I want to load a text file into a JEditorPane and then highlights some keywords such as while,if and else.I am using an EditorKit in order to style the JEditorPane. I have no difficulty while giving the input through the keyboard but lots of exceptions are thrown if i try to load the string from a file.

    Hi,
    I think the setCharacterAttributes(int offset, int length, AttributeSet s, boolean replace) will solve the problem.
    You can create your own Styled Document and set it to the Editor Pane.

  • How to highlight HTML source code in JEditorPane

    I used JEditorPane to display the HTML source code. Now I want to highlight some part of the HTML code.
    e.g. change the font or color of the second line in this piece of HTML code.
    I tried to highlight the text in HTML way, e.g.
    JEditorPane jep=new JEditorPane():
    jet.setContentType("text/html");
    jet .setText("<html><i>display styled text</i></html>");
    but it didn't work at all. As the text I want to highlight is alreay a part of the HTML code.
    I have to sort it out ASAP. as the deadline of my project is coming...
    any advice is appreciated.
    Thanks so much..:)

    "In order to display the original html source code (not the effect made by HTML code ) i n JEditorPane,
    i can't use editorPane.setContentType("text/html"): As it will try to render the webpage with this piece of HTML code..
    e.g. here is the piece of html code i want to display in JEditorPane:
    <HTML><HEAD><TITLE>Department of Computer Science Home Page</TITLE>
    <META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
    <META content="MSHTML 6.00.2737.800" name=GENERATOR>
    </HEAD>.........</HTML>
    what i want to do is to highlight "Department of Computer Science Home Page" by setting it bold or italic."
    Not really sure what you're saying here, but it sounds like you mean that you want the HTML itself to change. If that's it just:
    <HTML>
    <HEAD>
      <TITLE>Department of Computer Science Home Page</TITLE>
      <META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
      <META content="MSHTML 6.00.2737.800" name=GENERATOR>
    </HEAD>
    <BODY color='blue' bgcolor='white'>
      <tr>
       <td bgcolor=yellow>Department of Computer Science Home Page</td>
      </tr>
    </BODY>
    </HTML>FWIW HTH, B4N
    ~Bill

  • JEditorPane - backmapping highlighted text to source html document

    Hello everyone,
    I have the following problem: I display a HTML document in JEditorPane. Then I highlight some chunk of text and get the start and the end selection offsets by using getSelectionStart() and getSelectionEnd() methods, respectively. What I would like to know is the exact position (character offset) of the highlighted text in the original HTML document that is being displayed.
    Does anybody know the solution for that?
    Thanks.

    I don't think it's possible. The parser builds a Document out of the text and doesn't keep the original source text. For example if your html is like this:
    String text = "<html><body>     some     text     </body></html>";All the multiple spaces between the text is parsed out.
    Use a JTextPane and use attributes. Its easier to work with than using HTML.

  • Text highlighting in a JEditorPane

    Hi everyone.
    I was wondering if you could help me with a slight problem im experiencing. I have a JEditorPane which displays HTML . I've added a search tool to my app that search for text in the JEditorPane and when it finds the search string it highlights the text
    dealingsHTML.select( nPosition, nPosition + toFind.length() );This works ok, but ONLY if i first click in the JEditorPane, then perform the search. If i dont click in the JEditorPane first then it won't highlight the text. Any ideas how I could get around this problem? Obviously it's beneficial to have the text highlighting.
    BBB

    Thanks for the tip-off camickr, what they suggested didnt work for me (dont know why) but from that I searched a few other threads and found the solution, so thanks.
    i found using the select(int,int) method to not be supported by highlighting when the object didnt have focus. So i used a combination of setcaretposition and movecaretposition and the setselectionvisible(boolean) method which works as desired: -
    dealingsHTML.setCaretPosition( nPos );
    dealingsHTML.moveCaretPosition( nPos + toFind.length() );
    dealingsHTML.getCaret().setSelectionVisible(true);

  • Trying to get a JEditorPane to highlight the full width of a displayed line

    I have displayed the wep page in JEditorPane . Now I'm trying to get a JEditorPane to highlight the full width of a displayed line. All the examples I've tried only highlight the textual content. For example if I have content such as this:
    + Here is some text +
    + some more text +
    within a JEditorPane represented by the box above, then highlighting the first row highlights only the 'Here is some text' (represented between [ and ] below).
    [ Here is some text ]
    [some more text ]
    I would like it to highlight the full width of the JEditorPane like the following:( ie Inspecting the Html element in firebug ....)
    l Here is some text l
    l some more text l
    l_________________________l
    Is there a way to do this?
    Edited by: arunnprakash on Mar 27, 2009 7:59 AM

    Take a look here:
    [http://tips4java.wordpress.com/2008/10/29/line-painter/]
    [http://www.java-forums.org/awt-swing/10862-how-select-highlight-entire-row-jtextpane.html]
    db

  • Highlight Text PROGRAMMATICALLY in JEditorPane

    Hi,
    I am printing some text on a JEditorPane. I want to highlight some words in a diffferent color. I want to do that programmatically. I have tried select(), setSelectionStart, setCaretPosition and everything. But in vain.
    Can someone please help?
    Thanks in advance
    sjl

    You need to play with attributes. This thread should get you started:
    http://forum.java.sun.com/thread.jsp?forum=57&thread=342068

  • How to highlight an html page that has been loaded in an JEditorPane

    Hi,
    I am creating a small application that loads an html ebook and the user will be able to highlight some phrases or words and then save the ebook. In my first step I just want when I load again the ebook the highlighted phrases to appear again. In my final step I want to create a file with the changes and when the ebook loads to combine the files to appear like the user has made it.
    So please help first how I can highlight the words and in general if you can give me some hints how I should work to get the application with the way I want.
    Thanks in advance

    That number looks up to this:
    Everymac.com: Apple Power Macintosh G4 400 (AGP)
    AGP refers to Accelerated Graphics Port. Those models were a replacement for the earliest G4 tower model, which had only a PCI graphics slot. They were long-lasting and solid, until Apple added the second processor in the Mirrored Drive Doors model and Heat and Cooling issues became a serious problem. But do not ever power it up without the processor heatsink in place.
    After you replace the battery, the PRAM can remember. But What it remembers is garbage. You should attempt to reset the PRAM.

  • Not able to highlight text. Help please?

    Hi I am trying to build a tool which is going to be used to to load an html book and the make some notes on it. Now I am trying to highlight. I am in thye very beginning so I just try to highlight a small part from the begginig not the user, this is my next step. But even I think that I don't have a problem with my code as I have used as base a program that is working actually my rpogram doesn't highlight anything.
    Here is the class I make the highlight
    import java.io.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.text.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.util.HashMap;
    import javax.swing.*;
    import javax.swing.text.*;
    import javax.swing.event.*;
    import javax.swing.undo.*;
    public class ViewClass extends JFrame {
      private JFrame frame = new JFrame(); // main window
      private JPanel panel = new JPanel(new BorderLayout()); //panels to aid layout
      private JPanel panel2 = new JPanel(new GridLayout(1, 1));
      private JMenuBar menuBar=new JMenuBar();
      JMenu file = new JMenu("File");
      JMenu help = new JMenu("Help");
      JMenuItem open=new JMenuItem("Open");
      JMenuItem save=new JMenuItem("Save");
      JMenuItem exit=new JMenuItem("Exit");
      JMenuItem manual=new JMenuItem("Manual");
      JMenuItem about=new JMenuItem("About");
      JButton buttonH=new JButton();
      JButton buttonB=new JButton();
      JButton buttonT=new JButton();
      private JToolBar toolBar = new JToolBar();
      private JScrollPane scrollPane = new JScrollPane();
      private Model callingModel;
      private Controller theController;
        private static JEditorPane createEditorPane() {
        JEditorPane editorPane = new JEditorPane();
        editorPane.setEditable(false);
        java.net.URL helpURL = ViewClass.class.getResource("mexico_city.html");
        System.out.println(helpURL);
        if (helpURL != null) {
            try {
                editorPane.setPage(helpURL);
            } catch (IOException e) {
                System.err.println("Attempted to read a bad URL: " + helpURL);
        } else {
            System.err.println("Couldn't find file: mexico_city.html");
         return editorPane;
    public ViewClass(Model m) {
         callingModel =m; //retrieve link to model
         theController = new Controller(callingModel); // create controller
         //set up visual features of the window
         frame.setTitle("Take a note");
         frame.setJMenuBar(menuBar);
         menuBar.add(file);
         menuBar.add(help);
         file.add(open);
         file.add(save);
         file.addSeparator();
         file.add(exit);
         help.add(manual);
         help.add(about);
         file.setMnemonic(KeyEvent.VK_F);
         help.setMnemonic(KeyEvent.VK_H);
         //frame.getContentPane().setLayout(new BorderLayout());
         toolBar.add(buttonH);
         buttonH.setIcon(new ImageIcon("H.gif"));
         buttonH.setToolTipText("Highlight");
         buttonH.setActionCommand("Highlight");
         toolBar.add(buttonB);
         buttonB.setIcon(new ImageIcon("B.gif"));
         buttonB.setToolTipText("Bookmark");
         buttonB.setActionCommand("Bookmark");
         toolBar.add(buttonT);
         buttonT.setIcon(new ImageIcon("T.gif"));
         buttonT.setToolTipText("Take a note");
         buttonT.setActionCommand("Noting");
         JEditorPane editorPane = createEditorPane();
         scrollPane = new JScrollPane(editorPane);
         MyHighlightPainter h = new MyHighlightPainter(Color.yellow);
         Highlighter hilite = editorPane.getHighlighter();
         try
              hilite.addHighlight(155, 1155,h);
         catch(BadLocationException ex)
              System.out.println(ex.getMessage());
        frame.getContentPane().add(panel);
        frame.getContentPane().add(panel2);
        panel.add(toolBar, BorderLayout.PAGE_START);
        panel.add(scrollPane, BorderLayout.CENTER);
       frame.getContentPane().add(panel, BorderLayout.CENTER);
       panel.add(new JScrollPane(editorPane) );
       exit.addActionListener(theController);
       about.addActionListener(theController);
       buttonH.addActionListener(theController);
       buttonB.addActionListener(theController);
       buttonT.addActionListener(theController);
         //ensure the following statement is always last
         frame.pack();
         frame.setSize(1274,970);
         frame.setVisible(true);//and nobody sees it until we do this
         frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
       static class MyHighlightPainter extends DefaultHighlighter.DefaultHighlightPainter
    public MyHighlightPainter(Color r)
    super(r);
    }

    With interactive reports in APEX 3.1 you can use the pull down menu to highlight cells and or rows of data. You can apply many highlighting rules, that are evaluated in order. So high values can be green, low values red, and other values default. You can try this running the sample application on OTN:
    http://apex.oracle.com/pls/otn/f?p=2357:2
    Mike

  • Refreshing JEditorPane (Urgent) plz help

    hello programmers,
    i'm building an html editor:
    My html editor has a split pane, the 2 pane got of the split pane are JEditorPanes, one on which i write tag and the other i display them,... thankfully all's working great, my syntax is highlighting and the html is displayed well but i've got the following problem:
    when i save a html page , i wanna my browser (on the right side of the slipt pane) to display the html page... it's ok .. it displays it with the method JHTMLEditorPane.setPage(file:/// directory/ file) but the problem is that when i save the page again using the same filename... my html page on the JHTMLEditorPane stays the same... it does not update...
    is their a refresh function for the JEditorPane? how can i update my JHTMLPane to reflect the changes i've brought to it? ONe thing , the page changes when i save it by aother file name..... PLz help it's very urgent!!!!!!!
    Bernard

    Have you tried to close and then re-open the file in your editorpane after you've saved?
    It will work when you change the name because it has to open the file as new. Java can't dynamically update values upon files like C does with pointers.

Maybe you are looking for

  • How to Test the individualmapping field and conditions...

    Hi Frnds, I done mapping from source to destination as per tech spec in my scenario based on some conditions i used node functions also.. But my question is how to test the every mapping filed , condition is correct or not, what i used node function

  • 8 Drives Inside of a Mac Pro?

    Hello All: Just wondering if any of you have used this and if so, what your opinions of it were: http://www.maxupgrades.com/istore/index.cfm?fuseaction=product.display&product_i d=158 Do you think something like this is worth it? Would you even consi

  • First attempt at php

    I also posted this in the General discussion forum for DW, as I was not sure where it will be picked up. I have just uploaded my first PHP script. This file should display a form to enable data input but the code is displayed instead, I cannot figure

  • Collective invoice not bring header text of all orders

    Hello everyone. By generating a collective invoice just brings me a header text of the first order. How can I do to bring the header text of each order? I am running tests on VOTXN, but can not. Thank you very much in advance. A greeting.

  • Sync interrupted

    Desktop manager successfully begins Intellisync process. It processes the handheld calendar, then reads from the Outlook calendar. After it has "read" all the records in the Outlook calendar, it stops working and delivers an error report: "Blackberry