jeditorpane

How do you set the tab size in a JEditorPane?

懵懂的女人 提交于 2019-11-29 03:59:08
A JTextArea 's tab size can easily be set using setTabSize(int) . Is there a similar way to do it with a JEditorPane ? Right now, text with tabs in my pane looks like: if (stuff){ more stuff; } And, I'd prefer a much smaller tab stop: if (stuff){ more stuff; } As JEditorPane is designed to support different kinds of content types, it does not provide a way to specify a "tab size" directly, because the meaning of that should be defined by the content model. However when you use a model that's a PlainDocument or one of its descendants, there is a "tabSizeAttribute" that provides what you are

Wrapping HTML text in a JEditorPane inside a JScrollPane

余生长醉 提交于 2019-11-29 02:42:37
In an application, I'm using uneditable JEditorPanes as a sort of a generic UI widget that can display somewhat complex content (HTML will do the trick), wrap text lines and catch mouse clicks. Not sure if JEditorPane is a good choice for this, so feel free to suggest alternatives. The following sample code works fairly well: import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import javax.swing.JEditorPane; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.ScrollPaneConstants; public class Main { private static JPanel

How should HTML for Java components reference resources?

心不动则不痛 提交于 2019-11-28 04:05:09
问题 Resources for HTML (style sheets, images etc.) might not be loaded correctly when: A Swing app. is distributed, or when it is put into a Jar file. The HTML is generated at run-time. How can such resources be accessed reliably in the HTML? 回答1: HTML from a Jar file that links resources (e.g. CSS or images) by relative references will work just fine. E.G. This example loads HTML (that has a relative reference to an image) from a Jar. import javax.swing.*; import java.net.URL; class ShowHtml {

Show HTML file in JEditorPane

被刻印的时光 ゝ 提交于 2019-11-28 02:04:48
I am working on a Swing application in which I have to show HTML files. I am using JEditorPane control for it. It is showing the content of HTML file but not in the same format as originally in the actual HTML file. JEditorPane does not support the object element. Rather than loading the object file its just showing ? . Is there any other inbuilt control in Swing to browse the HTML file rather than JEditorPane ? I am using the following code: JEditorPane HtmlPane= new JEditorPane(); File file1= new File("path of the file"); HtmlPane.setContentType("text/html"); HtmlPane.setEditable(false);

Highlighting few of the words of a text file opened in a frame

荒凉一梦 提交于 2019-11-28 01:27:58
I am opening a file in a frame and I wish to highlight few of the words.As I understand,I need to traverse the content of the file. How do I traverse through the contents and what is the related property that I may use for the purpose of highlighting? UPDATE : MY CODE GOES SOMETHING LIKE THIS private JEditorPane editorpane; JScrollPane editorScrollPane; public TextEditor() { editorpane = new JEditorPane(); editorpane.setEditable(false); if (filename != null) { try { File file = new File(filename); editorpane.setPage(file.toURI().toURL()); } catch (IOException e) { e.printStackTrace(); System

How do you set the tab size in a JEditorPane?

房东的猫 提交于 2019-11-27 18:11:39
问题 A JTextArea 's tab size can easily be set using setTabSize(int) . Is there a similar way to do it with a JEditorPane ? Right now, text with tabs in my pane looks like: if (stuff){ more stuff; } And, I'd prefer a much smaller tab stop: if (stuff){ more stuff; } 回答1: As JEditorPane is designed to support different kinds of content types, it does not provide a way to specify a "tab size" directly, because the meaning of that should be defined by the content model. However when you use a model

Wrapping HTML text in a JEditorPane inside a JScrollPane

孤街醉人 提交于 2019-11-27 16:58:03
问题 In an application, I'm using uneditable JEditorPanes as a sort of a generic UI widget that can display somewhat complex content (HTML will do the trick), wrap text lines and catch mouse clicks. Not sure if JEditorPane is a good choice for this, so feel free to suggest alternatives. The following sample code works fairly well: import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import javax.swing.JEditorPane; import javax.swing.JFrame; import javax.swing.JPanel; import javax

JEditorPane set foreground color for different words

ε祈祈猫儿з 提交于 2019-11-27 16:29:49
I am currently working on a text editor, and I have this code which make the background of the specific word different from the others, but I want the foreground to edit color and not the background. Here's the code I have: import java.awt.BorderLayout; import java.awt.Color; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JEditorPane; import javax.swing.JFrame; import javax.swing.JTextPane; import javax.swing.text.AbstractDocument; import javax.swing.text.BadLocationException; import javax.swing.text.DefaultHighlighter;

Clickable HTML link in JEditorPane using replaceSelection method

人走茶凉 提交于 2019-11-27 16:26:56
I searched how to make clickable links in JEditorPane , and I found this question: Is it possible to create programs in Java that create text to link in Chrome? It was very useful, but my code uses a repetition statement to add links in a loop: JEditorPane jep = new JEditorPane(); jep.setContentType("text/html"); jep.setEditable(true);// Because replaceSelection can't work with disabled edit for ( int i = 1; i <= 3; i++ ){ jep.replaceSelection( "Welcome to <a href='https://stackoverflow.com/'>StackOverflow i </a>."); } jep.setEditable(false); Now it shows me just text without clickable links.

Java JScrollBar Design

六月ゝ 毕业季﹏ 提交于 2019-11-27 15:54:18
I want customize the JScrollBar Design. I use Mac to develop the app with eclipse. I already tried to scrollPane.getVerticalScrollBar().setBackground(Color.BLACK); but nothing happen. My code: scrollPane = new JScrollPane(scriptView); scrollPane.setBorder(BorderFactory.createEmptyBorder()); scrollPane.getVerticalScrollBar().setUnitIncrement(6); window.getContentPane().add(scrollPane); The Object scriptView is from the class JEditorPane . How it should look: Thanks for every help. I guess you are looking for a transparent scrollbar. This is just presented as an idea(NOT tested code): import