• Post Reply Bookmark Topic Watch Topic
  • New Topic

Unable to refresh the content of JEditorPane.  RSS feed

 
rahul kumar
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
let me give u a brief description of what i am doing and what i want.
i am creating a html page through my program and then setting the page of JEditorPane to the html page created. this all thing occurs on the actionevent of a ComboBox.
What i have done...
on the ActionEvent of JComboBox i check which item was selected and then
1. i call a method user made create_report(int)
the int argument is the current selected item of the combobox, this int argument decides different set of coding in the html page.
In the create_report method i create a FileWriter and then write the code in the file. then closes the Filewriter object.Now one thing important that every time the create_report() method is called the previous html file is replaced by the new file as per the FileWriter's constructor bhehaviour.
2.in next step i create a URL object to that file
3.in the 3rd and the last step i call the setPage method of JEditorPane and pass the URL.
Now what the problem is the JEditor only shows the first html page created but not the next and onwards but when i check the html file in the browser the contents have correctly changed according to the JCombobox selection being made.
I am unable to understand why this is happening.

Code.....
//////////////////////////////////////////////
these three if constructs are inside the actionPerformed method
if(report.getSelectedIndex()==0)
{
try
{
create_report(0);
URL location=new URL("file:Report.html");
//report_pane.setText("");
System.out.println(report_pane.getPage());
report_pane.setPage(location);
parent.doLayout();
}
catch(Exception e)
{
System.out.println("Exception in(report, if report.getSelectedindex) :"+e);
}
}
*******************
if(report.getSelectedIndex()==1)
{
try
{
create_report(1);
URL location=new URL("file:Report.html");
//report_pane.setText("");
System.out.println(report_pane.getPage());
report_pane.setPage(location);
parent.doLayout();
}
catch(Exception e)
{
System.out.println("Exception in(report, if report.getSelectedindex) :"+e);
}
}
******************************
if(report.getSelectedIndex()==2)
{
try
{
create_report(2);
URL location=new URL("file:Report.html");
//report_pane.setText("");
System.out.println(report_pane.getPage());
report_pane.setPage(location);
parent.doLayout();
}
catch(Exception e)
{
System.out.println("Exception in(report, if report.getSelectedindex) :"+e);
}
}

*************************
create_report() method....
private void create_report(int index)throws Exception
{
FileWriter fw=new FileWriter("Report.html");
fw.write("<html>");
fw.write("<body>");

if(index==0)
{
fw.write("<font color=blue ><b><center> TOTAL NUMBER OF COMPLAINTS & AMOUNT GENERATED </center></b></font>");
}
if(index==1)
{
fw.write("<font color=blue ><b><center> TOTAL NOUMBER OF COMPLAINTS HANDLED BY THE EMPLOYEE </center></b></font>");
}
if(index==2)
{
fw.write("<font color=blue ><b><center> TOTAL NUMBER OF COMPLAINTS MADE BY CLIENTS </center></b></font>");
}

fw.write("</body>");
fw.write("</html>");
fw.close();
}
//////////////////////////////////////////////
 
rahul kumar
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Pls guys reply soon ,don't get afraid of the size of code pls read it, it is really very simple and do reply soon as i am running out of time.
 
Michael Morris
Ranch Hand
Posts: 3451
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Rahul,
I haven't worked much with JEditorPane, but the problem may be that if the current URL that the page is set to equals the URL passed in by setPage [ie oldURL.equals(newURL)] it may not redisply the content. If this is the case, you may want to use two differnt file names and toggle between them. Let me know if this works.
Hope this helps
Michael Morris
SCJP2
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!