Basically I have a file called FlowLayout.html and I want to read it into the JEditorPane. I have all the code up to that point but I don't know how to open the file in the pane.
JEditorPane jtfInfo = new JEditorPane();
jtfInfo.setEditable(false);
p3.add(jtfInfo);
public void getFlowLayout(){
jftInfo.setContentType("text/html");
//I dont know this step and setContentType gives me an error in netbeans Cannot find symbol
}
You can just call the setPage() method with URL pointing at the FlowLayout.html file:
public void getFlowLayout(){
jftInfo.setPage(new URL("path to file"));
}
From the Java Tutorial: How to Use Editor Panes and Text Panes:
"The setPage method opens the resource pointed to by the URL and figures out the format of the text (which is HTML in the example). If the text format is known, the editor pane initializes itself with the text found at the URL. A standard editor pane can understand plain text, HTML, and RTF. Note that the page might be loaded asynchronously, which keeps the GUI responsive but means that you should not count on the data being completely loaded after the call to setPage returns."
Related
I'm trying to open a URL in my application through the displayHelpResource(href) function.
But I'm being shown the following :
This content cannot be dispalyed in a frame
To help protect the security of information you enter into this website, the publisher of this content does not allow it to be displayed in a frame.
I've understood that the site is blocking the Frame access. What can be done to open the desired URL using the displayHelpResource(href) function.
You can add noframes=true to the href you stop frames being used
http:xxxxx?noframes=true
The noframes=true text is removed from the href by the help system before it is actually used.
I have this Desktop email client program that I'm currently working on in Java and I want to show the incoming mail content inside a JEditorPane.
I've created an HTMLEditorKit and set it as an editor kit for the JEditorPane control like this:
editorPane.setEditorKit(htmlEditorKit);
And for some messages, it works fine but for some others, it shows its background as a blue-colored one. I tried to add a stylesheet rule to the kit, but it didn't work.
What could have been the problem?
Any comments will be welcome.
EDIT:
JEditorPane txtContent = new JEditorPane();
txtContent.setEditable(false);
txtContent.setBackground(Color.WHITE);
txtContent.setBounds(316, 110, 598, 545);
kit = new HTMLEditorKit();
txtContent.setEditorKit(kit);
HTMLDocument doc = (HTMLDocument)kit.createDefaultDocument();
txtContent.setDocument(doc);
txtContent.setText("HTML content here.....");
When I put "HTML content here....." part inside an html file with Notepad, it shows the right thing.
But when I put the exact same content inside the JEditorPane like the above, it shows different styling(blue background).
I have a serious problems with richtext field in my app. (Domino R901). I have extracted the scenario into simple Xpage with just one field and submit button only.
I have simple XPage now, with one field and submit button. RT field looks like this:
<xp:inputRichText id="inputRichText1" value="#{docui.body}"></xp:inputRichText>
Plus there is a standard button which runs JAVA action below with full submit:
This action is called on button click:
public void r(DominoDocument docui) throws NotesException {
Document cdoc = docui.getDocument(true);
if (cdoc.hasItem("body")){
print("Body exist");
} else {
print("Body doesnt exist");
}
docui.setDocument(cdoc);
}
Now when I enter some text into rich text field (CKEditor) and click on submit, it reloads the page (full submit) and I can see the text in CKEditor properly. Now when I do it 2nd time, text disapear and even in my JAVA code it says, that 'Body doesnt exist'. The problem seems to lie in fact, that CKEditor doesnt send content to server, when there is no change to it ... see here richtext control doesn't store the input content . I understand this behaviour for saved existing document, but when you have a new document, it simply doesnt submit value during second submit because it doesnt changed between requests. But because its a new unsaved document the value is simply discarded / lost . Is there any workaround how to deal with this?
How can I open an HTML page and show it in a text area? (If I choose the HTML file with the JFileChooser, how can I open that page and show it in the text area?)
URL url = new URL(String s);
JEditorPane pane = JEditorPane(url);
But how can I find the link of the HTML file for inserting as s, here!?
A TextArea is for displaying/editing text, not for showing formatted HTML.
JEditorPane supports HTML markup, but only a rather limited subset.
For full HTML support, you're going to need third-party components. Look at the answers to this question for links.
Format the HTML with a <pre> tag
I guess you can use any properly formatted URL a browser would use e.g.
http://stackoverflow.com/questions/1239454/how-can-i-open-an-html-page-and-show-it-in-a-text-area
But then again Java is very keen on security and you might not be allowed to use certain URLs in your environment.
And like Michael Borgwardt said - the JEditorPane's support of HTML is very limited and some tags (i think <div> is one of them) as well as JavaScript are not supported.
For implementation of a simple browser have a look at this
JEditorPane Tutorial
I have a swing application that sends commands to server and receives result in XML format. I need to transform this into HTML via XSLT and then display result HTML on the panel. The problem is that the only Swing component which is able to display HTML - JEditorPane - takes either URL or javax.swing.text.StyledDocument as a source.
Option with URL doesn't work for me because I have to save my html as a file on the file system first and I'd like to avoid this.
So I have a gap between in-memory result of XSL transformation and javax.swing.text.StyledDocument, which can be rendered by JEditorPane or JTextPane.
How to transform one to another? Or are there any other Swing solutions to display HTML from some in-memory source(DOM or String or whatever)?
Thank you in advance for help.
Is there a reason that JEditorPane.setText() does not work for you?
I use JEditorPane all the time and I've never pulled the displayed data from a file or URL. So it is possible. Just need to figure out why it's not working for you.
To be specific:
editor.setContentType( "text/html" );
editor.setText( "<html><body>Hello, world</body></html>" );
What about JeditorPane.setText() ?