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 6 of 6

Thread: problems with rendering HTML using JEditorPane

  1. #1
    Junior Member
    Join Date
    Apr 2013
    Posts
    6
    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,828
    My Mood
    Hungover
    Thanks
    147
    Thanked 703 Times in 595 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.
    How to Ask Questions the Smart Way
    Static Void Games - GameDev tutorials, free Java and JavaScript hosting!
    Static Void Games forum - Come say hello!

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

    Default Re: problems with rendering HTML using JEditorPane

    the content of myhtml.htm

    <HTML>
    <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=windows-1252">
    <TITLE>Jurisprudence Online - G.R. No. 12</TITLE>
    <META NAME="subject" CONTENT="Jurisprudence Online - IN RE: MARCELINO AGUAS">
    <META NAME="description" CONTENT="Jurisprudence Online - IN RE: MARCELINO AGUAS">
    <meta name="keywords" content="Jurisprudence Online"><head>

    </head>

    <body rightmargin="70px" leftmargin="70px"> <font size=4px>
    <br><center><img src="http://www.ustcivillaw.com/wp-content/uploads/2010/04/sscms.gif"></img></center><p align="center">EN BANC </P>

    <P><B> <center>G.R. No. 12 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;August 8, 1901</P>
    <P>In the matter of the proceedings against MARCELINO AGUAS for contempt of the COURT OF FIRST INSTANCE OF PAMPANGA.</B></P>
    <P><I>Claudio Gabriel, for appellant.<BR>
    Office of the Solicitor-General Araneta, representing the respondents.</I></P>
    <P><B>SMITH, <I>J.:</B></I></P>
    <P ALIGN="JUSTIFY">It appears from the record in this matter that on the 29th of August, 1900, during the progress of a trial then being held before the Court of First Instance at Bacolor, in the Province of Pampanga, the court had occasion to caution Angel Alberto, a witness in the case, not to look at the attorney for the defendant but to fix his attention on the judge who was at the time examining him. It seems that the witness did not give heed to this warning, and the judge thereupon arose from his seat and approaching the witness, seized him by the shoulders, and using the expression, "Lingon ang mucha" ("Look at me"), either shook him, as insisted by the attorney for the defendant, or only turned him about, as claimed by the judge and others. Whether the witness was shaken or only turned about, at all events "seizing him," brought the defendant's attorney to his feet, who, protesting against the action of the judge as coercive of the witness, demanded that a record be made of the occurrence and that the further hearing of the case be postponed. Two days afterward the clerk entered in his record as recital of the incident substantially as above, and also a statement that on other and prior occasions the attorney, Marcelino Aguas, had been wanting in respect to the court by making use of "improper phrases," and by interrupting opposing counsel in their examination of witnesses. The court on this record adjudged the attorney to be in contempt of court and suspended him from the practice of his profession for a period of twenty days. The attorney appealed, but his appeal having been disallowed by the lower court, he asked to be heard in justification, which was granted.</P>
    <P ALIGN="JUSTIFY">On the hearing in justification evidence was taken touching the contempt alleged to have been committed by Se&ntilde;or Aguas, from which the court found that during the trial of the case of <I>Roberto Toledo vs. Valeriano Balatbat</I>, the judge, having had occasion to seize the witness, Alberto Angel, by the shoulders to turn him around, Se&ntilde;or Aguas, attorney for defendant, had risen from his seat in a "menacing attitude," and "with a voice and body trembling"protested that the action of the judge was coercive of the witness; and further that his attention being called to the fact that he was wanting in respect to the court and that he should sit down, he waived his right to go on with the trial and moved a postponement of the hearing. On this finding the court again adjudged the attorney guilty of contempt of court, and suspended him from the practice of his profession for a period of twenty days. From this judgment Se&ntilde;or Aguas appealed to this court.</P>
    <P ALIGN="JUSTIFY">In our opinion the action of the judge in seizing the witness, Alberto Angel, by the shoulder and turning him about was unwarranted and an interference with that freedom from unlawful personal violence to which every witness is entitled while giving testimony in a court of justice. Against such conduct the appellant had the right to protest and to demand were respectfully made and with due regard for the dignity of the court. The only question, therefore in this case is, Was the appellant respectful and regardful of the court's dignity in presenting his objection and asking that it be recorded in the proceedings? The witnesses say and the judge finds that "his attitude was menacing" (<I>bastante amenazadora</I>) in the moment of making his protest, but beyond that there is nothing in the record which even tends to show that he was disrespectful to the court or unmindful of its dignity. In our opinion both testimony and finding state a mere conclusion which, in the absence of the facts from which it was deduced, is wholly valueless to support a judgment of contempt. The statement that the attorney's attitude was "menacing" tended no more to competently establish the alleged offense of contempt than if the witnesses had testified and the court had found that his conduct was "contemptuous or lacking in respect." The specific act from which it was inferred that his attitude was menacing should have been testified to by the witnesses and found by the court, and failing that, the record does not show concrete facts sufficient to justify the conclusion that he was disrespectful to the court or offensive to its dignity.</P>
    <P ALIGN="JUSTIFY">The judgment appealed from must therefore be reversed, and it is so ordered, with costs<I> de oficio</I>.</P>
    <P><I>Arellano, C.J., Cooper, Willard, Torres, and Ladd, JJ.,</I> concur.<BR>
    <I>Mapa, J.,</I> did not sit in this case.</P>
    <br><br><br><center>University of Santo Tomas, Faculty of Civil Law
    � 2010 All Rights Reserved.<br><br>

    </center></body> </html>

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

    Default Re: problems with rendering HTML using JEditorPane

    the content of myhtml.htm

    <HTML>
    <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=windows-1252">
    <TITLE>Jurisprudence Online - G.R. No. 12</TITLE>
    <META NAME="subject" CONTENT="Jurisprudence Online - IN RE: MARCELINO AGUAS">
    <META NAME="description" CONTENT="Jurisprudence Online - IN RE: MARCELINO AGUAS">
    <meta name="keywords" content="Jurisprudence Online"><head>

    </head>

    <body rightmargin="70px" leftmargin="70px"> <font size=4px>
    <br><center><img src="http://www.ustcivillaw.com/wp-content/uploads/2010/04/sscms.gif"></img></center><p align="center">EN BANC </P>

    <P><B> <center>G.R. No. 12 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;August 8, 1901</P>
    <P>In the matter of the proceedings against MARCELINO AGUAS for contempt of the COURT OF FIRST INSTANCE OF PAMPANGA.</B></P>
    <P><I>Claudio Gabriel, for appellant.<BR>
    Office of the Solicitor-General Araneta, representing the respondents.</I></P>
    <P><B>SMITH, <I>J.:</B></I></P>
    <P ALIGN="JUSTIFY">It appears from the record in this matter that on the 29th of August, 1900, during the progress of a trial then being held before the Court of First Instance at Bacolor, in the Province of Pampanga, the court had occasion to caution Angel Alberto, a witness in the case, not to look at the attorney for the defendant but to fix his attention on the judge who was at the time examining him. It seems that the witness did not give heed to this warning, and the judge thereupon arose from his seat and approaching the witness, seized him by the shoulders, and using the expression, "Lingon ang mucha" ("Look at me"), either shook him, as insisted by the attorney for the defendant, or only turned him about, as claimed by the judge and others. Whether the witness was shaken or only turned about, at all events "seizing him," brought the defendant's attorney to his feet, who, protesting against the action of the judge as coercive of the witness, demanded that a record be made of the occurrence and that the further hearing of the case be postponed. Two days afterward the clerk entered in his record as recital of the incident substantially as above, and also a statement that on other and prior occasions the attorney, Marcelino Aguas, had been wanting in respect to the court by making use of "improper phrases," and by interrupting opposing counsel in their examination of witnesses. The court on this record adjudged the attorney to be in contempt of court and suspended him from the practice of his profession for a period of twenty days. The attorney appealed, but his appeal having been disallowed by the lower court, he asked to be heard in justification, which was granted.</P>
    <P ALIGN="JUSTIFY">On the hearing in justification evidence was taken touching the contempt alleged to have been committed by Se&ntilde;or Aguas, from which the court found that during the trial of the case of <I>Roberto Toledo vs. Valeriano Balatbat</I>, the judge, having had occasion to seize the witness, Alberto Angel, by the shoulders to turn him around, Se&ntilde;or Aguas, attorney for defendant, had risen from his seat in a "menacing attitude," and "with a voice and body trembling"protested that the action of the judge was coercive of the witness; and further that his attention being called to the fact that he was wanting in respect to the court and that he should sit down, he waived his right to go on with the trial and moved a postponement of the hearing. On this finding the court again adjudged the attorney guilty of contempt of court, and suspended him from the practice of his profession for a period of twenty days. From this judgment Se&ntilde;or Aguas appealed to this court.</P>
    <P ALIGN="JUSTIFY">In our opinion the action of the judge in seizing the witness, Alberto Angel, by the shoulder and turning him about was unwarranted and an interference with that freedom from unlawful personal violence to which every witness is entitled while giving testimony in a court of justice. Against such conduct the appellant had the right to protest and to demand were respectfully made and with due regard for the dignity of the court. The only question, therefore in this case is, Was the appellant respectful and regardful of the court's dignity in presenting his objection and asking that it be recorded in the proceedings? The witnesses say and the judge finds that "his attitude was menacing" (<I>bastante amenazadora</I>) in the moment of making his protest, but beyond that there is nothing in the record which even tends to show that he was disrespectful to the court or unmindful of its dignity. In our opinion both testimony and finding state a mere conclusion which, in the absence of the facts from which it was deduced, is wholly valueless to support a judgment of contempt. The statement that the attorney's attitude was "menacing" tended no more to competently establish the alleged offense of contempt than if the witnesses had testified and the court had found that his conduct was "contemptuous or lacking in respect." The specific act from which it was inferred that his attitude was menacing should have been testified to by the witnesses and found by the court, and failing that, the record does not show concrete facts sufficient to justify the conclusion that he was disrespectful to the court or offensive to its dignity.</P>
    <P ALIGN="JUSTIFY">The judgment appealed from must therefore be reversed, and it is so ordered, with costs<I> de oficio</I>.</P>
    <P><I>Arellano, C.J., Cooper, Willard, Torres, and Ladd, JJ.,</I> concur.<BR>
    <I>Mapa, J.,</I> did not sit in this case.</P>
    <br><br><br><center>University of Santo Tomas, Faculty of Civil Law
    � 2010 All Rights Reserved.<br><br>

    </center></body> </html>

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

    Default Re: problems with rendering HTML using JEditorPane

    the content of the myhtml.htm. this post may have a duplicate since i got some admin message with the previous post i sent.

    <HTML>
    <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=windows-1252">
    <TITLE>Jurisprudence Online - G.R. No. 12</TITLE>
    <META NAME="subject" CONTENT="Jurisprudence Online - IN RE: MARCELINO AGUAS">
    <META NAME="description" CONTENT="Jurisprudence Online - IN RE: MARCELINO AGUAS">
    <meta name="keywords" content="Jurisprudence Online"><head>
     
    </head>
     
    <body rightmargin="70px" leftmargin="70px"> <font size=4px>
    <br><center><img src="http://www.ustcivillaw.com/wp-content/uploads/2010/04/sscms.gif"></img></center><p align="center">EN BANC </P>
     
    <P><B> <center>G.R. No. 12 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;August 8, 1901</P>
    <P>In the matter of the proceedings against MARCELINO AGUAS for contempt of the COURT OF FIRST INSTANCE OF PAMPANGA.</B></P>
    <P><I>Claudio Gabriel, for appellant.<BR>
    Office of the Solicitor-General Araneta, representing the respondents.</I></P>
    <P><B>SMITH, <I>J.:</B></I></P>
    <P ALIGN="JUSTIFY">It appears from the record in this matter that on the 29th of August, 1900, during the progress of a trial then being held before the Court of First Instance at Bacolor, in the Province of Pampanga, the court had occasion to caution Angel Alberto, a witness in the case, not to look at the attorney for the defendant but to fix his attention on the judge who was at the time examining him. It seems that the witness did not give heed to this warning, and the judge thereupon arose from his seat and approaching the witness, seized him by the shoulders, and using the expression, "Lingon ang mucha" ("Look at me"), either shook him, as insisted by the attorney for the defendant, or only turned him about, as claimed by the judge and others. Whether the witness was shaken or only turned about, at all events "seizing him," brought the defendant's attorney to his feet, who, protesting against the action of the judge as coercive of the witness, demanded that a record be made of the occurrence and that the further hearing of the case be postponed. Two days afterward the clerk entered in his record as recital of the incident substantially as above, and also a statement that on other and prior occasions the attorney, Marcelino Aguas, had been wanting in respect to the court by making use of "improper phrases," and by interrupting opposing counsel in their examination of witnesses. The court on this record adjudged the attorney to be in contempt of court and suspended him from the practice of his profession for a period of twenty days. The attorney appealed, but his appeal having been disallowed by the lower court, he asked to be heard in justification, which was granted.</P>
    <P ALIGN="JUSTIFY">On the hearing in justification evidence was taken touching the contempt alleged to have been committed by Se&ntilde;or Aguas, from which the court found that during the trial of the case of <I>Roberto Toledo vs. Valeriano Balatbat</I>, the judge, having had occasion to seize the witness, Alberto Angel, by the shoulders to turn him around, Se&ntilde;or Aguas, attorney for defendant, had risen from his seat in a "menacing attitude," and "with a voice and body trembling"protested that the action of the judge was coercive of the witness; and further that his attention being called to the fact that he was wanting in respect to the court and that he should sit down, he waived his right to go on with the trial and moved a postponement of the hearing. On this finding the court again adjudged the attorney guilty of contempt of court, and suspended him from the practice of his profession for a period of twenty days. From this judgment Se&ntilde;or Aguas appealed to this court.</P>
    <P ALIGN="JUSTIFY">In our opinion the action of the judge in seizing the witness, Alberto Angel, by the shoulder and turning him about was unwarranted and an interference with that freedom from unlawful personal violence to which every witness is entitled while giving testimony in a court of justice. Against such conduct the appellant had the right to protest and to demand were respectfully made and with due regard for the dignity of the court. The only question, therefore in this case is, Was the appellant respectful and regardful of the court's dignity in presenting his objection and asking that it be recorded in the proceedings? The witnesses say and the judge finds that "his attitude was menacing" (<I>bastante amenazadora</I>) in the moment of making his protest, but beyond that there is nothing in the record which even tends to show that he was disrespectful to the court or unmindful of its dignity. In our opinion both testimony and finding state a mere conclusion which, in the absence of the facts from which it was deduced, is wholly valueless to support a judgment of contempt. The statement that the attorney's attitude was "menacing" tended no more to competently establish the alleged offense of contempt than if the witnesses had testified and the court had found that his conduct was "contemptuous or lacking in respect." The specific act from which it was inferred that his attitude was menacing should have been testified to by the witnesses and found by the court, and failing that, the record does not show concrete facts sufficient to justify the conclusion that he was disrespectful to the court or offensive to its dignity.</P>
    <P ALIGN="JUSTIFY">The judgment appealed from must therefore be reversed, and it is so ordered, with costs<I> de oficio</I>.</P>
    <P><I>Arellano, C.J., Cooper, Willard, Torres, and Ladd, JJ.,</I> concur.<BR>
    <I>Mapa, J.,</I> did not sit in this case.</P>
    <br><br><br><center>University of Santo Tomas, Faculty of Civil Law
    � 2010 All Rights Reserved.<br><br>
     
    </center></body> </html>

  6. #6
    Junior Member
    Join Date
    Apr 2013
    Posts
    6
    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, 03: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, 03: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