HTML with swing

Hi,
Is there a swing component to display html?
How can I display an HTML file within a JFrame ?
Thanks!

Here's some sample code for printing a html file inside a JEditorPane.
private void displayHTMLFile() {     
/* HTMLEditorKit is used for displaying html files in JEditorPane */
HTMLEditorKit htmlKit = new HTMLEditorKit();
JEditorPane editPane = new JEditorPane();
editPane.setEditorKit( htmlKit );
editPane.setEditable( false );
try {
/* read the html file using an input stream reader */
InputStreamReader in = new InputStreamReader(
new FileInputStream( "try.html" ), "iso-8859-1" );
/* give the input stream reader to the htmlkit to read */
htmlKit.read( in, editPane.getDocument(), 0 );
} catch ( Exception e ) {
System.out.println(e.toString());
/* display the editor pane inside a scroll pane */
JScrollPane scroll     = new JScrollPane( editPane );
getContentPane().add( scroll, "Center" );                    
}     

Similar Messages

  • Entering data in an HTML with an Applet?

    I have a small application I made with Swing. now, I want to make it html for use with Explorer. and I have 2 challanges:
    1. How do I get use input in an Applet? (the example in the tutial only applies to showing text.
    2. How do I access the database with JDBC?
    Thanks, Benny.

    question 1 is:
    Can I use TextField or JTextField in an Applet to
    receive input from the user.Since an Applet is a Container... what do you think? And why didn'T you simply try or read the API? Or the Swing tutorial?
    Question 2:
    I only know about Applets. What I need to do is
    receive input from the user (e.g. first & last name,
    e-mail and phone number) and update the data into the
    database (currently MDB and MySQL in the near
    future).
    I know how to do this with swing and
    JDBC localy. but, how do I do it when my GUI
    is HTML / webpage?Signed applet and high hopes that nobody's using the packets sent by your applet to hack and wreck your DB.

  • Using Report tool with Swing Application

    I'd like to use a reporting tool (Crystal Reports or anything else) with Swing application. Could anyone help me?

    You have to pass the values are parameters to the Oracle Reports report. Take a look at this: http://www.oracle.com/technology/products/database/application_express/howtos/howto_integrate_oracle_reports.html
    Also you can search this forum for "Oracle Reports"
    Mike

  • 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.

  • How to link crystal report with swing

    I am developing applications in swing. I have done a report using crystal report.
    Now i don't know how to link it with swing. can anyone help me to solve this with some examles.
    thanx in advanz

    Hope these links are useful:
    http://www.must.de/default.html?Jareport.htm
    http://www.utdallas.edu/~pxm034000/files/integrating.html

  • Do I need to make an applet with swing point to the JRE 1.4 plug-in?

    Do I need to make an applet with swing point to the JRE 1.4 plug-in? I mean, in 1.3.1 plug-in, if you did not run your code through the HTML converter, the applet would still use the browsers JRE (JVM). However, with 1.4.0, it seems that you don't need to. Is this correct?

    When you ran an applet that has been compiled under 1.4 and needs classes or methods from 1.4 with an old HTML file (presumedly with the <object> tag that still refers to JRE 1.3+), the browser is going to look at the <object> tag and see that at least JRE1.3.1 is needed to correctly run the applet and since 1.4, which is higher than 1.3+, is on the system, it ignorantly proceeds to load and run the applet. The problem that you're going to run into is when you deploy the applet on the web and your viewer only have JRE1.3+, your applet which really needs 1.4, will crap out....
    ;o)
    V.V.

  • Can I build a GUI application with SWING only without [import java.awt.*;]

    I have seen several threads (in forums), books and tutorials about SWING and I see that they all mix SWING with AWT (I mean they import both Swing and AWT in their code).
    The conclusion that comes out is:
    It is good to learn about SWING and forget AWT as it won't be supported later. I have decided to do so, and I never include <<import java.awt.*;>> in my code.
    But I see that you cannot do much without <<import java.awt.*;>>. For example this line which changes the background color:
    <<frame.getContentPane().setBackground(Color.red)>>
    works only with <<import java.awt.*;>>. I have seen that codes in this and other forums import awt to change the background. Why is that?
    After all, I wonder, what can I do;
    My question is, can I change the background (and of course do all other things listener, buttons etc) without using <<import java.awt.*;>>.
    I would like to avoid using <<import java.awt.*;>> and using awt since my program will not work later.
    In addition, I believe there is no point to learn awt, which later will not exist.
    I know, I must have misunderstood something. I would appreceate it very much, if anyone could give me even a short answer.
    Thank you in advance,
    JMelsi

    Since swing is a layer on top of awt, AWT will exist for as long as swing does.
    If sun does ever remove AWT they will have to replace it something else swing can layer on to and you will probably only have to replace your import statements.
    The main difference is the way there drawn to the screen.
    You can do custom drawing on swing components but you can't on AWT.
    If your using a desktop PC system it's probably best to use swing just in case you wish to do some custom drawing.
    awt uses less memory than swing and is faster but swing can be extended. awt comes only as standard.
    Say for example you wish to implement a JButton with a ProgressBar below the button text, this can be done with swing!

  • 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?

  • Integrating crystal report with swing application

    Hi,
    Any body knows how to integrate crystal reports with swings?
    I'm posting this after a painful search in the net/forum.Any idea
    will be greatly apprecited.
    thanx.
    regards,
    jmos

    The best place to pick up sample code is straight from the horses mouth. [url http://www.businessobjects.com/products/dev_zone/java/default.asp?ref=devzone_main] Crystal java zone

  • Coloring a table cell with swing

    Hello,
    I am trying to write a java program in swing. Basically I am setting up a table and adding labels to the table's cells. Rather than displaying the label, the table is inserting the labels' string value. Here is a compilable example:
    import java.awt.GridBagLayout;
    import java.awt.GridBagConstraints;
    import java.awt.Insets;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JTable;
    import javax.swing.JScrollPane;
    import java.awt.*;
    public class TableTest extends JFrame {
         private final JTable table;
         private final GridBagConstraints constraints;
         private JLabel makeLabel(Color c){
              JLabel lab = new JLabel(" ");
              lab.setOpaque(true);
              lab.setBackground(c);
              //getContentPane().add(lab, constraints);
              return lab;
         public TableTest() {
            super("Visualizer");
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            getContentPane().setLayout(new GridBagLayout());
            constraints = new GridBagConstraints();
            constraints.insets = new Insets(3, 10, 3, 10);
            String[] columnNames = {"RED","YELLOW", "BLUE"};
            Object[][] data = { {makeLabel(Color.RED), makeLabel(Color.YELLOW), makeLabel(Color.BLUE) } };       
            table = new JTable(data, columnNames);
            table.setPreferredScrollableViewportSize(new Dimension(500, 70));
            table.setFillsViewportHeight(true);
            JScrollPane scrollPane = new JScrollPane(table);
            //Add the scroll pane to this panel.
            add(scrollPane);
            pack();
            setVisible(true);
         public static void main(String[] args) {
              new TableTest();
    }How do i modify this to actually show the labels? Thanks in advance.

    Why are you putting labels into the table's cells?
    Have a look at Sun's tutorial on tables to see how a custom renderer is used to display particular cells in a certain way. (And also for the whole rendering approach used by tables.)
    http://java.sun.com/docs/books/tutorial/uiswing/components/table.html#renderer
    (Swing questions are better asked in the Swing forum: http://forum.java.sun.com/forum.jspa?forumID=57)

  • 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.

  • 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?

  • Reversing with swing? Help!

    Alright, before you guys flip out and say post it to the swing forum, why does the swing forum say read only? Now I have searched the forum but cannot find anything that deals with swing and the kind I am doing. So if you can provide some advice or some help, it would be greatly appreciated. This is my last hurdle to tackle in my school project.
    I tried a StringBuffer approach but it kept giving me an error saying it would not work with JTextArea? Maybe the code was wrong?
    This needs to take the text on the screen which I have and post it reversed when the "Reverse" button is clicked... I have been searching the web and these forums and all the different reverse methods and theories are confusing me, I try to copy them and get them to work but I just keep receiving errors. What is the best way to do this with using GUI?
    else if (actionCommand.equals("Reverse"))
              reverseMemo = theText.getText();
    /*Is this where I would put the reverse code?*/          
    theText.setText(reverseMemo);
         }Thanks,
    Jess

    Just write a method to reverse the text
    read the string in reverse and start plugging the values into a string buffer (inside a loop of course)
    then display results:
    textfield.setText(stringbuffer.toString());
    This is my last hurdle to tackle in my school project.I highly doubt it.
    The fact you are asking this question shows me you did not learn anything about Java much less computer science. Your question has nothing to do with swing.

  • 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.

Maybe you are looking for

  • Time Machine not resolving on a previously used External Drive (Resolved)

    Not Often but I post on a resolved problem that might help. Please be aware that this involves using a root session that might be dangerous for your data if you don't know what you're doing. Problem: I had a Time machine dedicated drive that TM would

  • Deploy to Weblogic  JDBC open failure

    I have deployed successfully prior to the 7/1/2009 Jdeveloper release. When I tried to deploy using the new release I receive the same error messages no matter the technique. I used the ear sync set check box. This generates a web and jdbc module in

  • Assign message number 161 to message class F2

    Hi all, Whats tcode to assign message no 161-Vendor & already exists to message class F2-Master Data Maintenance: Customer, Vendor in? Then I will set as Error or Warning at tcode OBA5. Really appreciate your help Thanks

  • Benefits of Application Server over Web Server

    Hi I know it is very basic, but I would like to pose a question, and would really appreciate answers with some statistics and experience. I want to know what are the benefits of using application server over the traditional web servers. If I am using

  • My updates for iWork won't install via the Mac App Store

    Hello, I have iWork or Pages [5.5.1 (2111)], Numbers [3.5 (2109)] , and Keynote [6.5 (2110)] and I am told that there are 'updates' in the Mac App Store, but every time I click on them the download fails. No reason is ever given. I had iWork '09 on d