Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: problems with rendering HTML using JEditorPane

  1. #1
    Junior Member
    Join Date
    Apr 2013
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default problems with rendering HTML using JEditorPane

    i have this code to render a locally saved html file onto a jframe. i have the following problems with how the html was rendered:

    1. the texts of the 'webpage' do not wrap;
    2. in order to solve my problem in 1. above, i added a JScrollPane, problem is, the scrollbars do not appear.

    any help is appreciated. thanks.

    i have the code below:
    (main method -TryJEditor.java)
    import javax.swing.JFrame;
     
    public class TryJEditor {
     
    	public static void main(String[] args) {
     
    		TryHtml itry = new TryHtml();
    		itry.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    		itry.setSize(500, 300);
    		itry.setVisible(true);	
    	}
    }

    (and the class - TryHtml.java)

    import java.awt.*;
    import java.io.File;
    import java.io.IOException;
    import java.net.MalformedURLException;
    import javax.swing.*;
     
    public class TryHtml extends JFrame {
     
    	private JEditorPane HtmlPane;
    	private JPanel pane;
    	private JScrollPane scroller;
    	private String url = "file:///D:\\Java Exercise Programs\\TryJEditor\\myhtml.htm";
     
    	public TryHtml() {
    		super("title");
    		FlowLayout fl = new FlowLayout(FlowLayout.LEFT);
    		setLayout(fl);
     
    		pane = new JPanel();
    		try {
    			pane = new JPanel();
    			HtmlPane= new JEditorPane(url);			
    			HtmlPane.setContentType("text/html");
    			HtmlPane.setEditable(false);
    			HtmlPane.setSize(500, 250);	
    			scroller = new JScrollPane(HtmlPane, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
     
    		} catch (IOException e) {
    			e.printStackTrace();
    		}
     
    		pane.add(scroller);
    		add(pane);
    		pack();		
    	}
    }


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: problems with rendering HTML using JEditorPane

    It would help to have myhtml.html as well, since that file is required to run your code.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Junior Member
    Join Date
    Apr 2013
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: problems with rendering HTML using JEditorPane

    disregard.. i found some ideas from the internet.
    i just added this new line after creating the JScrollPane.

    scroller.setPreferredSize(new Dimension(int, int));

Similar Threads

  1. JEditorPane in a JScrollPane
    By Danjb in forum AWT / Java Swing
    Replies: 10
    Last Post: June 12th, 2011, 02:41 PM
  2. Java 3D Problems - Canvas 3d and QuadArray rendering
    By minime12358 in forum What's Wrong With My Code?
    Replies: 14
    Last Post: May 27th, 2011, 08:00 AM
  3. JEditorPane - following links within locally created HTML
    By davedude in forum AWT / Java Swing
    Replies: 1
    Last Post: January 21st, 2011, 04:32 PM
  4. Problems with rendering a jprogressbar
    By albertof in forum What's Wrong With My Code?
    Replies: 1
    Last Post: November 10th, 2010, 04:47 AM
  5. [SOLVED] writing html file in a jeditorpane
    By nasi in forum AWT / Java Swing
    Replies: 3
    Last Post: May 8th, 2010, 09:39 PM