Menu
  • HOME
  • TAGS

DocumentFilter: Why is replace() invoked and not insertString()?

java,swing,jtextcomponent,documentfilter

The insertString(...) method is invoked when you update the Document directly, by using the Document.insertString(...) method. The replace(...) method is invoked when the Document is updated by methods of the View (ie. the JTextField) when the user enters text or the user invokes Actions (cut, paste) associated with the text...

Font size in Jtextpane looks smaller then in other appliactions

java,fonts,size,jtextpane,jtextcomponent

Actually there is DPI difference of java (72pixels per inch) and windows (96 pixels per inch). To reflect your fonts properly you can multiply them on the 96/72 on Windows. You can override public Font getFont(AttributeSet attr) method of DefaultStyledDocument where retrieve font size from the attribute set and increase...

Not entering while loop

java,swing,file-io,io,jtextcomponent

file.createNewFile(); . . . BufferedReader br = new BufferedReader(new FileReader(file)); The reader works from an empty file that just has been created. Of course br.readLine() will return null immediately since the file is empty. Instead of the while loop, I would simply write: bw.write(textArea.getText()); ...

Swing insert image via ContentType(“text/html”);

java,html,image,swing,jtextcomponent

Try something more like... <img src='" + getClass().getResource("/path/to/image/image.jpg").toString() + "' .../> instead... Two main reasons your code isn't working... The src directory won't exist when the application is built and the image will be included in the resulting Jar file (assuming you're using something like Netbeans or are building it...

How to add JTextArea to JScrollPane?

java,swing,jscrollpane,jtextarea,jtextcomponent

You need to add your text component to JScrollPane. For example instead of: content.add(textComp, BorderLayout.CENTER); use: content.add(new JScrollPane(textComp), BorderLayout.CENTER); For more details refer to How to Use Scroll Panes. ...