Edit html in JEDITORPANE

HEllo friends!
I need your help, for editing html in editorpane.
I want to create a textarea in which the user type simple text than select some part of it & makes it bold, italic etc. by using an event of button or popup any thing.
So guide me that which textcomponent provide this , i already used JEditorPane, and insert tags manually but it is not good, if i try to overlap the tags og italic & bold.
So please help me is this any way pre built to provide these func. of add html tags in jeditorpane & use see the render html test in area.
than please provide me. at [email protected]
Thanks
import javax.swing.*;
import javax.swing.text.*;
import javax.swing.text.html.*;
import javax .swing.border.*;
import java.awt.*;
import java.awt.event.*;
import java.io.IOException;
public class TestJEditor extends JFrame {
Panel p1 = new Panel();
JButton b1 = new JButton("BOLD");
JButton b2 = new JButton("ITALIC");
BorderLayout borderLayout1 = new BorderLayout();
JScrollPane jScrollPane1 = new JScrollPane();
JEditorPane jEditorPane1 = new JEditorPane();
HTMLEditorKit editorKit = new HTMLEditorKit();
DefaultEditorKit defaultKit = new DefaultEditorKit();
public TestJEditor() {
super("Note");
this.getContentPane().add(p1);
//jEditorPane1.setEditable(false);
jEditorPane1.setEditorKit(editorKit);
p1.setLayout(null);
p1.add(jScrollPane1);
jScrollPane1.setBounds(10, 10, 350, 100);
jScrollPane1.getViewport().add(jEditorPane1, null);
b1.setBounds(370, 10, 100, 20);
p1.add(b1);
b2.setBounds(370, 40, 100, 20);
p1.add(b2);
b1.addActionListener(new ActionListener() {
     public void actionPerformed(ActionEvent e)
     // jEditorPane1.setEditorKit(defaultKit);
     String str = jEditorPane1.getText();
     System.out.println(str);
     String temp = jEditorPane1.getSelectedText();
     if(temp.indexOf("<B>") != 0)
     int start = str.indexOf(temp);
     int end = start + temp.length();
     System.out.println("start "+start+" end "+end);
     str = str.substring(0,start)+"<B>"+str.substring(start,end)+"</B>"+str.substring(end);
     jEditorPane1.setText(str);
     //System.out.println(jEditorPane1.getText());
b2.addActionListener(new ActionListener() {
     public void actionPerformed(ActionEvent e)
     String str = jEditorPane1.getText();
     System.out.println(str);
     String temp = jEditorPane1.getSelectedText();
     System.out.println("Italic");
     int start = str.indexOf(temp);
     int end = start + temp.length();
     str = str.substring(0,start)+"<I>"+str.substring(start,end)+"</I>"+str.substring(end);
     jEditorPane1.setText(str);
public static void main(String[] args) {
JFrame frame = new TestJEditor();
frame.setSize(600,500);
frame.addWindowListener(new WindowAdapter()
public void windowClosing(WindowEvent e)
System.exit(0);
//frame.pack();
frame.show();
}

Hi kashif10,
JEditorPane or JTextPane are the classes to use. You can have both bold and italic for a text portion.
See http://java.sun.com/products/jfc/tsc/articles/ for an overview of articles covering the swing text package.
Or try application SimplyHTML at http://www.lightdev.com/template.php4?id=3 it is open source and has a lot of documentation too.
Ulrich

Similar Messages

  • Problem to display Animated Gif from HTML into JEditorPane

    I have a problem displaying animated gif that comes from URL (HTML) into JEditorPane.
    Let me show you the source I have:
    * @author Dobromir Gospodinov
    * @version 1.0
    * Date: Dec 6, 2002
    * Time: 6:47:53 PM
    package test.advertserver;
    import javax.swing.*;
    import java.awt.*;
    import java.io.IOException;
    public class Test {
         public static void main(String[] args) {
              JFrame frame = new JFrame();
              JEditorPane ed = new JEditorPane();
              try {
                   ed.setPage("http://localhost:8200/servlet?key=value");
              } catch (IOException e) {
                   e.printStackTrace();
              JPanel panel = new JPanel();
              panel.setPreferredSize(new Dimension(500, 500));
              panel.add(ed);
              frame.getContentPane().add(panel);
              frame.pack();
              frame.setVisible(true);
    }Part of the returned from servlet HTML includes an img tag:
    <img src="/images/MyAnimatedGif.gif" alt="animated gif comment" width="480" height="50"  border="0">Let us assume that MyAnimatedGif.gif has 10 frames and gif is looped - when the 10th is dipslayed it has to display the 1st and so on.
    JEditorPane displays frames from 1 to 10 correctly but does not start from the first again. Instead JEditorPane displays a broken image.
    I locate where the problem arise:
    JEditorPane has an HTMLEditorKit that creates javax.swing.text.html.ImageView instance for every IMG tag.
    And here is the problem:
    ImageView has an ImageObserver necessary for the asynchronous image download. ImageObserver has the imageUpdate method. But this imageUpdate method is never called with ALLBITS flag raised up. Instead, after the last frame of MyAnimatedGif.gif is downloaded the imageUpdate method is called with flag ERROR raised up. Obviously this is a bug of Sun's implementation. Finaly the flag ALLBITS has to be received for normal end of image observing. But ALLBITS flag does not come.
    So, can anybody help me how to load an animated gif within JEditorPane completely.
    Thank You in advance,
    Dobromir Gospodinov
    P.S. If somebody of you wants to debbug what happens within ImageView will have to implement it (and related classes too, because of the limited package visability) borrowing the source from Sun's ImageView.

    I'm also having this problem with java 1.4.1 I discovered that some animated gifs work fine, while others stop animating. Running with java 1.3.1 fixed the problem. I'm going to report this as a bug
    Here's my code:
    import java.awt.*;
    import java.io.*;
    import javax.swing.*;
    public class AnimatedGifTester
    extends JFrame
    public static void main(String argv[])
    throws Exception
    new AnimatedGifTester();
    public AnimatedGifTester()
    throws Exception
    String[] images = new String[] {
    "http://www.gif.com/ImageGallery/Animated/Animals/Photographic/dog_running.gif",
    "http://www.gif.com/ImageGallery/Animated/Characters/Cartoon/java.gif",
    "http://www.webdeveloper.com/animations/bnifiles/anielg.gif",
    "http://www.webdeveloper.com/animations/bnifiles/cat2.gif",
    "http://images.animfactory.com/animations/animals/fish/big_fish_swimming_md_wht.gif",
    "http://www.webgenies.co.uk/images/martian.gif",
    "http://www.webdeveloper.com/animations/bnifiles/at_sign_rotating.gif",
    "http://www.webdeveloper.com/animations/bnifiles/arrow_1.gif",
    "http://www.gif.com/ImageGallery/Animated/Characters/Cartoon/javaacro.gif",
    "http://java.sun.com/products/java-media/2D/samples/suite/Image/duke.running.gif",
    "http://www.gif.com/ImageGallery/Animated/SouthPark/Cartoon/stan.gif"
    StringBuffer buffer = new StringBuffer("<html><body>");
    for (int idx = 0; idx < images.length; idx++)
    buffer.append("<img src='" + images[idx] + "'>");
    buffer.append("</body></html>");
    String html = buffer.toString();
    // save a copy of the html to open in a browser so we can see what it's
    // supposed to look like
    BufferedWriter writer = new BufferedWriter(new FileWriter("animatedGifTest.html"));
    writer.write(html);
    writer.close();
    JEditorPane editorPane = new JEditorPane("text/html", html);
    editorPane.setEditable(false);
    getContentPane().add(editorPane);
    setDefaultCloseOperation(EXIT_ON_CLOSE);
    setSize(new Dimension(400, 600));
    show();

  • Can't edit .html file in dreamweaver?

    Why can't I edit .html file in Dreamweaver CS 5.5 when it is not attached to a template?
    I have always been able to edit it every other time I have opened the file (since I built the site over two years ago).
    Now each time I try to edit it in Design mode, no matter where I click in the file the whole page gets a dark grey overlay and I can't get a curser.
    I am still able to edit the code directly but I do not want to be restricted.
    The last thing I did the last time I opened the file was paste Google Analytics code in just before the </head> tag. I did this to all the files on the site but this is the only one that isn't working. I have tried taking out this code but it makes no difference.
    I am using a 6 month old Macbook pro.
    Can anyone help me?

    In your stylesheet you have -
    .container {    overflow:hidden; width: 100%;}
    .container2 {   overflow:hidden; width: 646px; margin:0 0 10px 0}
    Try right clicking on the page in Design view and then selecting Element view > Full and see if that helps.

  • Plain Text will not display correctly, how can i edit html?

    Hello,
    my beloved MacBook Pro has been a godsend, however i have found that it is incapable of displaying Plain Text, in Text Edit, Safari (View Source), or Dreamweaver's code view. Thus, i am finding it impossible to view or edit html.
    the way it displays is either all jumbled and overlapping, or spread out over impossible distances. sadly i cannot post a picture.
    we also have a G3 and a G4 in the house, both running 10.3, and they also have the same issue with plain text.
    I have not found any topic on this, here or in google. can someone please help?
    thanks,
    Tobias
    macbook pro 2.33 3GB   Mac OS X (10.4.8)  

    Tom, very kindly, has got me most of the way to a happy ending.
    one or another font file or cache was causing the problem. i removed all fonts from Home/Library/Fonts, then ran FontFinagler, rebooted, and things display correctly.
    now i must figure out how to establish which fonts are suitable suitcases to be used.
    bests,
    tobias
    macbook pro 2.33 3GB    

  • Issues editing HTML on an existing site.

    I am attempting to replace the existing content in a site's left panel with custom HTML. 
    I refined the HTML working with a new blank subsite and was able to use the "Edit HTML" option directly in the Left Panel without adding a Content Editor Web Part. 
    When I go to the existing site I am unable to get the "Edit HTML" option within the panel itself and when I add a Content Editor Web Part it completely breaks my formatting. 
    Is there any way to apply HTML directly to an existing site panel without using a web part?

    Hi  ,
    According to your description, my understanding is that you want to customize the quick launch of your SharePoint 2010 site.
    For your issue, you can use the SharePoint web interface or SharePoint Designer 2010. You can have a look at the blog:
    http://sharepointpromag.com/sharepoint/four-ways-add-or-remove-quick-launch-menu-control
    http://msdn.microsoft.com/en-us/library/office/ms466994(v=office.14).aspx
    http://office.microsoft.com/en-in/sharepoint-server-help/configure-the-quick-launch-for-site-navigation-HA102130960.aspx
    Best Regards,
    Eric
    Eric Tao
    TechNet Community Support

  • Display HTML in JEditorPane

    Hi
    I am trying to display a String containing HTML text on a JEditorPane.
    I have downloaded the HTML from a webpage using sockets, and now I want to display the downloaded page. I have a project in school about sockets.
    This is why I can't use getPage(URL);
    The following is the code I am using:
    String temp = "String with HTML text"
    HTMLEditorKit htmlEdKit = new HTMLEditorKit();
    JEditorPane.setEditorKit(htmlEdKit);
    JEditorPane.setContentType("text/html");
    JEditorPane.setEditorKitForContentType("text/html", htmlEdKit);
    JEditorPane.setContentType("text");
    JEditorPane.setText(temp);
    When I run the code, all that is displaying is the raw HTML code, with all the tags. As I understand it, this is how it should be done.
    What is wrong, would appreciate some help.
    /David Mossberg

    it's not necessary to use socket but if use socket get the inputstream from it.
    in = socket.getinputstream(); //return inputstream from socket
    htmldoc = JEditorPane.getDocument(); //return the htmldoc in JEditorPane
    if(htmldoc.getlength()>0)
    htmldoc.remove(0,htmlDoc.getLength());//if the htmldoc has some content then remove it
    reader = new InputStreamReader(in);//construct a new reader from in
    JEditorPane.getEditorKit.read(reader,htmldoc,0); //read new content into the htmldoc from reader
    Hope the above code helps you.
    joney

  • Editing HTML file leaves temporary files lying about the place

    G'day
    CFB 2.0.1, installed as stand-alone on Windows 7 Enterprise 64-bit.  Although this has been the case since CFB 1.0, and on various Windows installs.
    Whenever I edit a HTML file (ie: with a .html extension), CFB creates  a temporary file in the same dir, eg: .tmp_charts.html.33659~ (the original file name is charts.html).  I've no problem with this - other than the fact it should not be necessary - but what I do have a problem with is that it does not tidy up after itself once it's done: the tmp files stay there.  This is a bit sloppy.
    I'm sure (100% sure) I've raised with this with Adobe in the past, and raised a bug for it, but it's not on the bug tracker for some reason.
    Can other CFB users test out what happens when they edit HTML files with CFB? Note: the tmp file does not show up in the navigator listing within CFB, but it is there in the file system if one looks with Windows Explorer.
    I'm going to raise a bug again (done: 3328624), in the hope this can be fixed.  It's a minor thing, but I'm sick of accidentally committing rubbish to my source control because I forget CFB can't tidy up after itself.
    Cheers.
    Adam

    Curious.
    Still: they should just not be there in the first place.  They don't appear for any other file type that I am aware of.
    Agreed!
    Come to think of it, I had another issue with CFB leaving bits around a while back.  Ahhh, now I can't remember exactly what the issue was.  I remember it had to do with mapping a networked drive.  When I would map a particular drive letter, say 'W', then start CFB it would create an entire folder hierarchy on there seemingly from a different server.  I know this because we have two different CF environments here; some server are running CF under JRun and others are running CF under WebSphere.  I only noticed this issue because I had mapped one of our JRun servers and all of a sudden it had portions of the WebSphere directory structure on there.  I think it had to do with a workspace in CFB but can't remember for sure.  I fixed it a while back by removing the offending setting in CFB.  Man, wish I could remember exactly what it was...

  • Edit HTML in Blog

    Hi All,
    Basically I'm fidelling around with the Blog function and I'm trying to add a youtube video to the blog using the HTML code from youtube, and choosing edit html from the toolbar and pasting the code in.
    When I press save the blog is blank. And when I press "edit html" again none of the code that I just pasted is there.
    I'm no shark at html, so am I doing something wrong?

    Emilliard,
    The html you are pasting is blacklisted. It's a security provision that Apple put in place for you. You can override it to allow the html, but you will have to create a custom whitelist on your server.
    First, grab this PDF: http://images.apple.com/server/macosx/docs/ExtendingYour_WikiServer.pdf
    Then read page 33. It references your YouTube problem specifically.
    Good luck,
    RyanR>

  • How do I edit HTML after publishing site?

    What does it mean to edit HTML after publishing the site? How exactly is that done? From another thread, it seems that re-publishing will overwrite that HTML - is that true? Thanks for any insight into this.

    This link may help:
    http://iwebfaq.org/site/iWebAlternativeHTML.html

  • Editing HTML through the browser itself

    Today, I went to JotSpot and reached the following page saying that Safari is not supported [from http://feedback.jot.com/KnownIssues/]:
    Mac Support
    <item>1. Mac support: WYSIWYG will work with the Firefox browser (free, open-source), but not with Safari. Safari does not allow you to edit HTML through the browser itself. Without this capability, we cannot offer WYSIWYG mode.
    Any idea why Apple did not implement this feature? Is it in the roadmap?
    Thanks!
    - Mazzaroth

    I do not know how JotSpot implements online editing, but I have been on sites using Safari which have allowed me to have an html editor with formatting buttons and a choice between wysiwyg and html editors.
    You can always send in a bug report using "Report Bugs to Apple" under the Safari menu.
    And for now, if you want to use JotSpot you can use Firefox.

  • How to edit html in iWeb

    How can I edit html in iWeb?

    but info was needed on how to edit / add additional coding as no obvious way of designing a typical 'Contact Us' form included in iWeb
    Then you should have said that in your topic.
    And if it did not answer the question, then say so in the same topic.
    Anyway, the HTML Snippet was invented for your purpose.
    So find the Contact Us code, usually a form, and paste it in the HTML Snippet.

  • How can I edit HTML code that was previously inserted?

    Inserting HTML code is easy enough - Object -> Insert HTML...
    But editing the code does not seem possible. It seems that it's necessary to delete the HTML object and reinsert it to make a change. What am I missing?

    Right click. I'm on my phone, but an option like "Edit HTML..." should be among the choices when an HTML embed object is selected.

  • My Firebug doesn't edit HTML, CSS etc.; the only option is "Delete element" or so... FF and Fbug are new versions, FF itself works perfectly. The Edit option looks like dead... Thank you.

    Firebug is supposed to show the changes of the site "in fly" while editing HTML code. But Edit is disabled permanently, only Remove (or Delete) element is functional

    Do you have the DOM Inspector installed?
    *DOM Inspector: https://addons.mozilla.org/firefox/addon/6622

  • Edit HTML text of an existing widget

    Hello
    I added an Instagram widget to my page that is working fine, except I want to see if it is possible to add a border to the photos so that it has a more uniform look. It has been a minute since I've worked in Muse and I have forgotten how to find the area where that HTML text is entered, and subsequently edited. Can someone please shed some light? I believe I would select the widget and then go to a menu in Muse. But there doesn't seem to be that menu item that would allow me to edit a pre-existing widget. Ugh
    As always, any insight would be ever so greatly appreciated.

    I discovered the problem. It's on the right click. And I recently started using a wierd Mac mouse. Haven't figured out the right click. Works fine on a regular mouse. That's where the "edit HTML" option lives. Thanks anyway, all. Best

  • Edit html template

    Hi ,
    I am working with SAP 4.7c having standalone ITS server. I am required to make some changes in the existing Z ITS Template to add a button over there.
    I tried doing hte same in se80 internet service html template-> html editor, but of no use. Even if I remove all the lines of code, the screen is comin  as it is.
    My question is, is using a SAP Webstudio must to edit html templates or it can be done in any html editor?
    if it can be done in any html editor then why my changes are not being reflected.
    Any inputs will be appreicated.
    regards
    Justin

    Sorry, there is a tippo, I mean Statictemplates. Using the Search you can find
    this [document|http://help.sap.com/saphelp_nw04/helpdata/en/44/313097196b2bb2e10000000a422035/frameset.htm]
    regards
    Tobias

Maybe you are looking for

  • This computer is already associated with an Apple ID

    I'm trying to download music I've purchased (in the past) via iTunes into my iMac. The past purchases were made [principally] via my iPad and, as a consequence, the actual music media is resident on my iPad. Since these music purchases, I've purchase

  • Lightroom 5 - Bug in Survey view?

    Hi all, Sorry if this isn't the right place for this, it's the first time I've used these forums and I couldn't find anywhere else to submit a bug report. I've recently started using Lightroom and have started with Lightroom 5.  I've found that somet

  • In Windows 2008 server 64 bit database problem

    Hi In windows 2008 server (64 bit) application is deployed and database is oracle 10g. I got the error ORA-06502: PL/SQL: numeric or value error: character string buffer too small for one storeprocedure. The same database is dump in window 2003 serve

  • How to Register a Report

    i have installed oracle financials on windows XP jst for learning purpose i am new to oracle financials RDBMS : 9.2.0.6.0 Oracle Applications : 11.5.10.2 i want to register a report now i have created first the executable for that report then in prog

  • Info From Text Fields

    Hi, i was jsut wondeirng how to get the information submitted from a text field. Like, let's say i have a text field, and when the user types what they want in it, and hits the "Submit" button, it writes that information to a file. Thanks in advance