HTML with AWT

Hi every body !
Can someone please tell me how I can manage HTML with a AWT component ?
With Swing, we for example use JEditorPane or JTextPane as I did for a JApplet (http://www.big-chat.com).
As it is for Applet, I want it to be avalaible in all browsers. But now, it is not the case !
Please help.
Thanks !

Why won't JApplet work in all browsers? Every browser that I know (that is graphical) supports the Java plug-in.
If you want to support the MS JVM in IE users without the plugin, well there are some things you should know:
1) MS is not shipping this anymore for newer systems (Win 2003 and XP SP1a).
2) It's Java version 1.1.4, so there's a whole heck of a lot of stuff that won't work.
3) It's going to be officially retired in 2007 (was supposed to be in Sept 2004, actually).
I highly doubt that there's an AWT-based HTML display component out there. There's not one written in Swing that is a complete, up-to-date browser as it is.
Just stick with the plugin.

Similar Messages

  • Printing HTML with Java Printing Service(JDK1.4 beta)

    Hi there!
    I'm currently checking out the new Java Printing Service (JPS) in the new JDK1.4 beta. This looks like a very promising printing API, with amongst others printer discovery and support for MIME types - but I have some problems with printing HTML displayed in a JEditorPane.
    I'm developing an application that should let the user edit a (HTML)document displayed in a JEditorPane and the print this document to a printer. I have understood that this should be peace-of-cake using the JPS which has pre-defined HTML DocFlavor amongst others, in fact here is what Eric Armstrong says on Javaworld (http://www.javaworld.com/javaone01/j1-01-coolapis.html):
    "With JPS, data formats are specified using MIME types, for example: image/jpeg, text/plain, and text/html. Even better, the API includes a formatting engine that understands HTML, and an engine that, given a document that implements the Printable or Pageable interface, generates PostScript. The HTML formatting engine looks particularly valuable given the prevalence of XML data storage. You only need to set up an XSLT (eXtensible Stylesheet Language Transformation) stylesheet, use it to convert the XML data to HTML, and send the result to the printer."
    After one week of reasearch I have not been able to do what Armstrong describes; print a String that contains text of MIME type text/html.
    I have checked the supported MIMI types of the Print Service returned by PrintServiceLookup.lookupDefaultPrintService(). This is the result:
    DocFlavor flavor = DocFlavor.INPUT_STREAM.GIF;
    PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
    aset.add(MediaSizeName.ISO_A4);
    aset.add(new Copies(2));
    PrintService[] service = PrintServiceLookup.lookupPrintServices(flavor,aset);
    if (service.length > 0) {
    System.out.println("Selected printer " + service[0].getName());
    DocFlavor[] flavors = service[0].getSupportedDocFlavors();
    for (int i = 0;i<flavors.length;i++) {
    System.out.println("Flavor "+i+": "+flavors.toString());
    Selected printer \\MUNIN-SERVER\HP LaserJet 2100 Series PCL 6
    Flavor 0: image/gif; class="[B"
    Flavor 1: image/gif; class="java.io.InputStream"
    Flavor 2: image/gif; class="java.net.URL"
    Flavor 3: image/jpeg; class="[B"
    Flavor 4: image/jpeg; class="java.io.InputStream"
    Flavor 5: image/jpeg; class="java.net.URL"
    Flavor 6: image/png; class="[B"
    Flavor 7: image/png; class="java.io.InputStream"
    Flavor 8: image/png; class="java.net.URL"
    Flavor 9: application/x-java-jvm-local-objectref; class="java.awt.print.Pageable"
    Flavor 10: application/x-java-jvm-local-objectref; class="java.awt.print.Printable"
    As you can see there is no support for text/html here.
    If anyone has a clue to what I'm missing here or any other (elegant, simple) way to print the contents of a JEditorPane, please speak up!
    Reply to: [email protected] or [email protected] or here in this forum

    Since you have 'printable' as one of your flavors, try this using a JTextPane (assuming you can dump your HTML into a JTextPane, which shouldn't be a big problem)...
    1. Have your JTextPane implement Printable
    ie. something like this:
    public class FormattedDocument extends JTextPane implements Printable 2. Read your HTML into the associated doc in the text pane.
    3. Implement the printable interface, since you have it as one of your available flavors (I'd imagine everybody has printable in their available flavors). Something like this:
    public int print(Graphics g, PageFormat pf, int pageIndex) {
            Graphics2D g2 = (Graphics2D) g;
            g2.translate((int)pf.getImageableX(), (int)pf.getImageableY());
            g2.setClip(0, 0, (int)pf.getImageableWidth(), (int)pf.getImageableHeight()); 
            if (pageIndex == 0)
                setupPrintView(pf);
            if (!pv.paintPage(g2, pageIndex))
                return NO_SUCH_PAGE;
            return PAGE_EXISTS;
        }Here's my setupPrintView function, which is executed once on page 0 (which still needs some polishing in case I want to start from page 5). It sets up a 'print view' class based on the root view of the document. PrintView class follows...
    public void setupPrintView(PageFormat pf) {
    View root = this.getUI().getRootView(this);
            pv = new PrintView(this.getStyledDocument().getDefaultRootElement(), root,
                               (int)pf.getImageableWidth(), (int)pf.getImageableHeight());Note of obvious: 'pv' is of type PrintView.
    Here's my PrintView class that paints your text pane line by line, a page at a time, until there is no more.
    class PrintView extends BoxView
        public PrintView(Element elem, View root, int w, int h) {
            super(elem, Y_AXIS);
            setParent(root);
            setSize(w, h);
            layout(w, h);
        public boolean paintPage(Graphics2D g2, int pageIndex) {
            int viewIndex = getTopOfViewIndex(pageIndex);
            if (viewIndex == -1) return false;
            int maxY = getHeight();
            Rectangle rc = new Rectangle();
            int fillCounter = 0;
            int Ytotal = 0;
            for (int k = viewIndex; k < getViewCount(); k++) {
                rc.x = 0;
                rc.y = Ytotal;
                rc.width = getSpan(X_AXIS, k);
                rc.height = getSpan(Y_AXIS, k);
                if (Ytotal + getSpan(Y_AXIS, k) > maxY) break;
                paintChild(g2, rc, k);
                Ytotal += getSpan(Y_AXIS, k);
            return true;
    // find top of page for a given page number
        private int getTopOfViewIndex(int pageNumber) {
            int pageHeight = getHeight() * pageNumber;
            for (int k = 0; k < getViewCount(); k++)
                if (getOffset(Y_AXIS, k) >= pageHeight) return k;
            return -1;
    }That's my 2 cents. Any questions?

  • Java Applets with AWT

    Hi,
    I have the problem to display the applet with AWT. If I am running the same applet in the internal server it works fine.If I am running through the web its giving Class not found exception.That web server also is mapped into the same server.
    Here is the code.
    import java.applet.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.util.*;
    public class NotHelloWorldApplet extends Applet
    public void init()
         try{
              setLayout(null);
              Label label1= new Label("Hello World!");
              label1.setSize(200,200);
              add(label1);
         }catch(Exception e){System.out.println(e);}
    <html><body>
    <applet
    code="NotHelloWorldApplet"
    codebase="."
    width=600 height=400
    >
    </applet>
    </body></html>
    can anyone help me please.
    Thanks

    Hello,
    Even I executed the program. Its works fine. I guess you must be having problem with the codebase. Just change the address in the codebase from current directory to the address where the class file is there and also change the permissions(set attributes to 755) of the class file. Hope this helps you.
    Regards,
    Sarada.

  • I have made a webpage in HTML with several links to JPGs / GIFs. The text matter opens perfectly but not the images. Please help me

    I have made a web page in HTML with several links to JPGs / GIFs. While text matter opens up perfectly, but not the images. Please help me.
    == This happened ==
    Every time Firefox opened
    == User Agent ==
    Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; CTS Version; .NET CLR 1.1.4322; .NET CLR 2.0.50727)

    URL of that web page?

  • Importing HTML with Javascript

    Hi folks,
    I have multiple (but simple) HTML forms that need to be imported as they are. Basically, I want to avoid the work of editing each button's Javascript manually in Acrobat, so I have the form ready in HTML with some JavaScript. Each form button has an onClick event calling the function below. The form works well in a browser, but, unfortunately, when I try to import it, the Javascript embedded in the page header disappears and the buttons do not work as programmed.
    Is there anyway to import the HTML *WITH* the Javascript?
    Here is the embedded Javascript code (pretty simple):
    <head>
    <script type="text/javascript">
    function DisplayCost(){
    var numPass = 0;
    var numTIDS = 0;
    var numExp = 0;
    var amtPass = 0;
    var amtTIDS = 0;
    var amtExp = 0;
    var amtTotal = 0;
    for(j=1; j <= 4; j++)
    tester = document.batch.elements["a" + j];
    exp_tester = document.batch.elements["b" + j];
    for( i = 0; i < tester.length; i++ ){
      if( tester[i].checked == true ){
    //   alert(tester[i].value)
       if(tester[i].value == "35") { numPass += 1; amtPass += parseInt(tester[i].value);
                if (exp_tester.checked == true) { numExp += 1; amtExp += parseInt(exp_tester.value);}}
       if(tester[i].value == "55") { numTIDS += 1; amtTIDS += parseInt(tester[i].value);
    if (exp_tester.checked == true) { numExp += 1; amtExp += parseInt(exp_tester.value);}}
       if(tester[i].value == "0") {exp_tester.checked=false}
    if(document.getElementByName('numPass') != null) { document.getElementByName('numPass').value = numPass;
           document.getElementByName('amtPass').value = amtPass; }
    if(document.getElementByName('numTIDS') != null) { document.getElementByName('numTIDS').value = numTIDS;
           document.getElementByName('amtTIDS').value = amtTIDS;}
    document.getElementByName('numExp').value = numExp;
    document.getElementByName('amtExp').value = amtExp;
    document.getElementByName('amtTotal').value = amtPass + amtTIDS + amtExp;
    </script>
    </head>
    Any help wuld be much appreciated.
    Regards,
    CodeChaser

    As it has already been said, there are fundamental differences between HTML "documents" and PDF documents. This also applies to JavaScript. Acrobat JavaScript and web browser JavaScript have things in common, and that is called the "Core" (get Flanagan's JavaScript, the Definitve Guide, published by O'Reilly, and you will see very clearly what objects etc. are relevant, and what not. Also, the document object model in PDF and in HTML are fundamentally different. And the field events are fundamentally different as well (as there is no onClick event in PDF, but mouseUp is used for clicking.
    What you can do, if you develop both, HTML forms and PDF forms, is to separate everything user interface-related from the raw (core) functions. The core functions can be used in either place, if their arguments are neutral, and you define them accordingly in your respective documents.
    You also can create your HTML form, and then get it into Acrobat, using WebCapture. The fields will be created, as well as labels etc. You will nevertheless rename your fields, in order to make them usable. Adding JavaScript to the appropriate events will be rather simple and straightforward.
    It would really be worthwile to have a closer look at the Acrobat JavaScript documentation (which is part of the Acrobat (X) SDK, downloadable from the Adobe website.
    For heavy duty application, you might look at a rather high-end forms design tool, OneForm Plus by Amgraf, which does create PDF forms and HTML forms from the same document, and is pretty good when it comes to the look of the forms. It also creates back-end code which is used to process submitted data. It is then also possible to have hybrid workflows when data gets displayed in PDF, and in HTML in the subsequent step and vice versa.
    Hope this can help.
    Max Wyss.

  • JMenu with AWT component

    dear friends;
    i have added menu bar in Jframe which is containes menues.
    AWT component is added the the same frame .
    problem is:
    menues are overlapping with awt component while i clicked the menu bar.
    dear friends help me immediately.
    thank u

    dear friends help me immediately.It's your own fault or combining Swing and AWT widgets. You're not supposed to do that, as it can lead to strange effects. Like this one.

  • How avoid of dialog in MS Word 97 during Save As HTML with JACOB...

    How to avoid of dialog "Microsoft HTML Conversion" in MS Word 97 during Save As HTML with JACOB. Dialog has this type of content: This document contains characters that are not in the current language encoding. To preserve them, choose cancel and select the appropriate language encoding. For multilingual documents, use UTF-8.

    It's not a JACOB issue, probably you have to direct your question to some Microsoft newsgroup (about Microsoft Word 97 automation using OLE/COM)

  • HTMLBody property occasionally returns HTML with no BODY

    Hi,
    We have an application that can store away .MSG files saved out previously from Outlook. This program allows the user to reply to these emails and, as part of this, gets Outlook to open the message so that it can extract information. It does this using the
    CreateItemFromTemplate() method:
    item = outlook.CreateItemFromTemplate(file_path)
    The problem is that, for some .MSG files, when we access item.HTMLBody property we get back html with no <BODY>, except for a comment:
    <HTML>
    <HEAD>
    <META NAME="Generator" CONTENT="MS Exchange Server version 14.02.5004.000">
    <TITLE></TITLE>
    </HEAD>
    <BODY>
    <!-- Converted from text/plain format -->
    </BODY>
    </HTML>
    Now this email does contain text which you can see if you look at the original email in Outlook, and I would expect the above code to always return HTML, converted if necessary, but this doesn't appear to be the case.
    This might be considered 'normal' behaviour, but it doesn't happen for me if I drag back one of these MSG files from the customer site to my development PC and try it here...So why would Outlook behave differently (and can it be fixed)?

    MAPI_E_NOT_ENOUGH_MEMORY in the GetProps tab is perfectly fine.  What are the contents of these properties when you actually select them?
    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!
    Yes, I figured that the MAPI_E_NOT_ENOUGH_MEMORY is not an issue itself. The contents of these properties appear to be ok when viewed in Outlook Spy. However, as stated, our software uses Outlook OLE to get the HTMLBody / Body of a MSG file, and that's where
    it goes wrong by not returning the text correctly (if at all). I'm just guessing that there is a connection between this Outlook OLE issue and the MAPI_E_NOT_ENOUGH_MEMORY value you see via Outlook Spy.

  • HTML with iWeb

    Hi,
    I just got the iWeb program, im trying to access the html code to add extra's to my site.
    Currently I am just closing down iWeb and editing through a text program, but im wondering if there is a way to view the html within iWeb so i dont have to close everything down, etc.
    Also when i do this, all changes to the html have to be after im done editing with iWeb because the changes wont load when i load my site in iWeb.
    Any help would be good, thanks.

    You can't view html with iWeb, and any custom html
    you add via a text editor or other means will be
    erased whenever you republish the page using iWeb.
    It really isn't an appropriate tool for what you
    want to do, at least not in this version.
    That is a real BUMMER! After spending many hours over this weekend setting my site up, I need to add a bit of html at the end of my welcome page:
    It is a dynamic weather report.
    I figured out how to add it with a text editor, but every time the file is edited in iWeb and then published, the added code is erased! I hope there will be a way to deal with this WITHIN iWeb soon.

  • Is it possible to export a muse page as and individual html with associated css?

    Is it possible to export a muse page as and individual html with associated css? 

    Yes, Muse has an Export as HTML feature.

  • Table Header not Recurring - when Generate PDF from HTML with tables

    Hello,  It is not working as expected...and I'm not sure if the functionality is supported.  Want to create PDF from html document. The html document contains a html table that typically contains a large number of rows.  To make reading easier the html table used thead and tbody elements, and their children, so that when the table extends across pages when printed the header element recurs on each page.  However, the header element is not recurring in the generated PDF document (it only occurs in the first row of the table).  Just wondering if you have tried or used this functionality (created PDF from html with table with headers and the PDF included the table with recurring table header.  And if so, did you do anything special to make it work.  Thanks for any insight.

    If there's a problem with that package, I suggest you speak to the developer of that package and ask them to investigate.  It's not an Oracle supplied package so you are wrong to look for help here.

  • Generate XML report then display like HTML with specified formate

    Hello,friends
    I want to generate XML report then use XSL to parse it,report will display like HTML with specified formate like attachment,any ideas?
    Thank you
    Alb

    Hi Ray,
    I don't why I can not upload any format picture,so I listed the display as below:
    Test Result                                                                                                  Company Logo
    SN                   1111                                                                                     User                          Operator
    Status              Fail                                                                                       Factory                     SE
    Product            xxx                                                                                       Tester                        xxx
    Start time         xxx                                                                                        Line                          xxx 
    Test time          xxx
    NAME                               STATUS           VALUE                          LOW               HIGH                   RULE
    1.0 Pass/Fail     Test           Passed             True                             True                                             EQ 
    2.0 Less than    Test            Failed               15                                10                                                LT
    3.0 String Value Test           Passed          A string from the limit file   A string
                                                           End of Report
    Could you give me some suggestions?
    Thanks a lot
    Alb

  • JTextArea HTML with embedded JTabbedPane

    I need a JTextArea to display HTML with an embedded JTabbedPane.
    From a high level, it should look as follows:
    HTML
    JTabbedPane
    HTML
    I basically want to nest the JTabbedPane into HTML above and below it.
    Any ideas?

    Hi Grok,
    I suggest using a JTextPane. JTextPane can handle HTML and you can also embed components into it.
    Good Luck,
    Avi.

  • Problems with awt.Toolkit on Tomcat

    Hello! I'm trying to get the Default Toolkit (java.awt.Toolkit.getDefaultToolkit() ) to determine the scrren size of the client, and Tomcat keeps throwing an Exception - now it's the website's Tomcat and the one on my localhost - there it worked.. Is there another way to determine the client's screen size in JSP (not JavaScript!)?? Thanx!

    first, the previous poster was right - learn how these protocols are interacting before you try something like you want to do - and they're right, you can't use the AWT toolkit to find out ANYTHING about the client.
    HTTP is stateless. so it's like this:
    browser request -> your code on server, jsp completely exeutes, generates html -> html PLAIN old html goes to the browser. in that order. no exceptions. ergo, all your code has executed once the browser starts getting data (buffers on the server not withstanding).
    As to why you're getting the exception, the server you are trying to run it on is most likely running in a mode called "headless", that is, there is no windowing api available to the JVM, so any awt calls will fail anyway. It works on your box because you are probably running a full windowing os, such as windows or Linux with gnome or kde. it just happens to return the correct screen size because that's the screen size of your screen, not the screen of the browser that it's outputting to. (try running your code locally and making your browser window small, you'll be dismayed that the rendered HTML is not the "right" size - because the screen size call was based on your resolution, NOT the size of the requesting browser window.
    if the last 2 sentences don't make sense, re-read them until they do.
    best of luck, sorry you're learing these frustrating lessons this way.

  • Strangeness Using HTML with JTabbedPane

    I'm getting some weird behavior when using html format for a JTabbedPane. It seems when I create tabs using HTML, it works fine, but when I subsequently try to change the tab title using JTabbedPane.setTitleAt(), the title doesn't change. The title doesn't change only when I create it with html. If I use "normal" text, the title changes fine.
    I imagine JTabbedPane has a problem with html. I am using version 1.3 and compiling with JBuilder. Below is an example of my program. Uncomment mentioned lines to see it react strangely.
    Any help would be appreciated.
    -joel
    package junk;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class BugExample extends JFrame {
    BugExample() {
    super( "Bug Example" );
    JTabbedPane tabs = new JTabbedPane();
    JPanel aPan= new JPanel();
    //html for tab index 0
    tabs.addTab("<html><center><font face=\"Dialog\" size = -1><b>Rate 1: " +
    "<font color=#008040>5.6%</b></font></font></center></html>", new JPanel());
    //"Normal" text for tab index 0. If I use this, then the setTitleAt works
    // properly. To try this, make sure the previous addTab() is commented out
    // tabs.addTab("Rate 1:5.7%", new JPanel());
    //html for tab index 1
    tabs.addTab("<html><center><font face=\"Dialog\" size = -1><b>Rate 2: " +
    "<font color=#008040>9.2%</b></font></font></center></html>", new JPanel());
    getContentPane().add(tabs);
    //Uncomment next line and run again using the html style addTab() for index 0.
    // I would think the tab at index 0 would show this new text
    // In fact, it will if I do not use html for index 1.
    // tabs.setTitleAt(0, "Rate it again");
    setSize( 400, 220 );
    public static void main(String[] args) {
    BugExample frame = new BugExample();
    frame.addWindowListener( new WindowAdapter() {
    public void windowClosing( WindowEvent e ) {
         System.exit(0);
    System.err.println("Starting");
    frame.setVisible(true);

    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class BugExample extends JFrame {
    BugExample() {
    super( "Bug Example" );
    JTabbedPane tabs = new JTabbedPane();
    JPanel aPan= new JPanel();
    //html for tab index 0
    tabs.addTab("<html><center><font face=\"Dialog\" size = -1><b>Rate 1: <font color=#008040>5.6%</b></font></font></center></html>", new JPanel());
    //"Normal" text for tab index 0. If I use this, then the setTitleAt works
    // properly. To try this, make sure the previous addTab() is commented out
    // tabs.addTab("Rate 1:5.7%", new JPanel());
    //html for tab index 1
    tabs.addTab("<html><center><font face=\"Dialog\" size = -1><b>Rate 2: <font color=#008040>9.2%</b></font></font></center></html>", new JPanel());
    getContentPane().add(tabs);
    //Uncomment next line and run again using the html style addTab() for index 0.
    // I would think the tab at index 0 would show this new text
    // In fact, it will if I do not use html for index 1.
    tabs.setTitleAt(0, "Rate it again");
    setSize( 400, 220 );
    public static void main(String[] args) {
    BugExample frame = new BugExample();
    frame.addWindowListener( new WindowAdapter() {
    public void windowClosing( WindowEvent e ) {
    System.exit(0);
    System.err.println("Starting");
    frame.setVisible(true);

Maybe you are looking for

  • How do I reset an iPod for a different user

    How do I reset an iPod for a different user

  • Mail doesn't seem to be receiving all messages

    I'm using Mail 5.2 in Lion. For the last couple of days, my mac.com address seems to be getting only a very limited number of messages. Like mailing lists that usually have 25-30 messages in the morning only have 6-8 in the morning. Sent an email to

  • Why have I been charged twice and what for?

    I have been charged two amounts, I presume for my landline to skype service. I would like to know why, and what this payment has been taken for? I Have been using this service since 2011 and cannot remember this happening before. PayPal states that [

  • Spamassassin isn't doing it's job properly

    I have a strange feeling...wait, I'm sure, that Spamassassin isn't working as it should be. The fact is I receive tons of spam e-mails, mostly from one or two sources recently, and every single time I'm marking those as spam in my KMail. It doesn't h

  • PR from MRP should not go to Release

    Dear All, How to control that PR generated from MRP Run should not go to Release Process. Regards, Pardeep Mlaik