jtextpane

Adding mouselistener to JLabel/JButton inserted in JTextPane

自作多情 提交于 2019-12-12 11:16:50
问题 I have a problem where when I try and add a mouselistener to a JLabel or JButton in a JTextPane I get the error "cannot be converted to Mouselistener by invocation conversion". I would prefer to have the component in a JEditorPane. I also heard a HyperlinkEvent could be used. Basicly I want a component that can be right/left clicked in a JEditorPane(preffered)/JTextPane. Any help would be appreciated Now it works (sortof) it only recives right clicks and I need to not draw button edges. Can I

Setting font size to 0 causes CGAffineTransformInvert: singular matrix error

社会主义新天地 提交于 2019-12-12 04:54:44
问题 I have a JTextPane and when a user clicks a button, I want certain portions of the text to "hide" StyleConstants.setFontSize(style,0); StyleConstants.setForeground(style,textPane.getBackground()); accomplished this perfectly, however it is also raising the following error: Java[20425] : CGAffineTransformInvert: singular matrix. Is there a way to accomplish what I'm doing (set font size to 0) without getting this error? Thanks! 回答1: The TextPane logs different types of messages (order matters)

How can I change the background color of an uneditable JTextPane in Java?

≯℡__Kan透↙ 提交于 2019-12-12 04:03:59
问题 I have a JTextPane that has pane.setEditable(false) which forces it to have a 'greyed-out' background color. After trying setBackground(Color.WHITE) (which doesn't work), I tried looking around the net for an answer but not managed to find one yet. Can anyone help me on this one please? 回答1: Note that for some Look and Feel like Nimbus that don't respect background property, you can use this code : private static class Painter extends javax.swing.plaf.nimbus.AbstractRegionPainter { private

Simple page size setting when printing JTextPane?

时光总嘲笑我的痴心妄想 提交于 2019-12-12 03:00:00
问题 I have a really simple Print function in my application that prints the contents of a Jtextpane. I want to set the default page size to A4 but after searching around I find lots of ways that involve book and document formater etc, I want to keep this as simple as possible. My code currently is: public void printy(){ JTextPane jtp = new JTextPane(); jtp.setBackground(Color.white); try { // open the file we have just decrypted File myFile = new File(deletefile + "mx.txt"); FileInputStream fIn =

JTextPane cannot render a concatenated HMTL string

半腔热情 提交于 2019-12-12 01:28:40
问题 If we set the text of a JTextPane with a String with HTML tags, it returns the text with the HTML document tags. jtextPane.setEditorKit(new HTMLEditorKit()); String setHTMLText= "I am a String with HTML format...<html><font color="red">COLOUR RED<</font><html>"; jtextPane.setText(setHTMLText); jtextPane.getText() returns: <html> <head> </head> <body> I am a String with HTML format... <html> <head> </head> <body> <font color="red">COLOUR RED</font> </body> </html> </body> </html> If I try to

Java Regex - Not coloring all matching word in JTextPane

陌路散爱 提交于 2019-12-12 00:11:52
问题 I want coloring all word that matching with commment public WarnaText(JTextPane source) throws BadLocationException { source.setForeground(Color.BLACK); Matcher komen=Pattern.compile("//.+").matcher(source.getText()); while(komen.find()) { String getkomen=komen.group(); StyleContext sc = StyleContext.getDefaultStyleContext(); AttributeSet aset = sc.addAttribute(SimpleAttributeSet.EMPTY, StyleConstants.Foreground, Color.RED); aset = sc.addAttribute(aset, StyleConstants.FontFamily, "Concolas");

Error with making text bold and colored in JTextPane

你说的曾经没有我的故事 提交于 2019-12-11 23:26:51
问题 I am trying to create a text editor using a JTextPane that outputs the text as HTML. I want to include the options to bold, color and align the text. I am having an issue with changing the color of a selection of text that is a mix of bold and not bold. For example, if I have the text in the editor " bold text not bold text" and I highlight both words and try to change the color of the text, it changes the color and makes all of the text bold, instead of leaving the second word not bold. So I

JTextPane and empty filler space

試著忘記壹切 提交于 2019-12-11 19:29:02
问题 I have a JTextPane in a JScrollPane, and I want to add an empty "filler space" at the top of the JTextPane, so that the first actual text row in the JTextPane appears at the bottom of the JViewport . I have a vague idea of having perhaps an empty paragraph in the beginning of the JTextPane and modify it's height everytime the JViewport is resized.. Anyone have ideas how to implement such a thing? Perhaps there is an easier way? 回答1: You can use setMargin() to set margin space between

typed charcter of my keyboard without display it automoticlly on my JtextPane

寵の児 提交于 2019-12-11 19:13:00
问题 I have a question about use case of JtextPane . Indeed, I delevelop an application using an MVC architecture. My frame has a Jtextpane with keylistener to permit all user to edit text. But as MVC architecture wants (and as i want too), I have to control characters typed before display it on the JtextPane. So, I use the Observer/Observable pattern to update my JtextPane. But, how can I typed any charcter of my keyboard without display it automoticlly on my JtextPane. Indeed, when I press any

identify line in a jtextpane when the row number is entered

好久不见. 提交于 2019-12-11 18:02:05
问题 public static void setJTextPaneFont(JTextPane jtp, Color c, int start_index,int end_index) { MutableAttributeSet attrs = jtp.getInputAttributes(); StyleConstants.setForeground(attrs, c); StyledDocument doc = jtp.getStyledDocument(); doc.setCharacterAttributes(start_index, end_index, attrs, false); } i created above code to change the forground of of specific word when i enter the start ndex and end index.But now i need to change the the forground when i pass the row number,start_index, and