
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to change font size with HTML in Java Swing JEditorPane?
Use HTMLEditorKitt to change the font size with HTML. With that, use the JEditorPane setText() method to set HTML:
HTMLEditorKit kit = new HTMLEditorKit(); editorPane.setEditorKit(kit); editorPane.setSize(size); editorPane.setOpaque(true); editorPane.setText("<b><font face=\"Verdana\" size=\"30\"> This is a demo text with a different font!</font></b>");
The following is an example to change font size with HTML in Java Swing JEditorPane:
Example
import java.awt.BorderLayout; import java.awt.Container; import java.awt.Dimension; import javax.swing.JEditorPane; import javax.swing.JFrame; import javax.swing.text.html.HTMLEditorKit; public class SwingDemo extends JFrame { public static void main(String[] args) { SwingDemo s = new SwingDemo(); s.setSize(600, 300); Container container = s.getContentPane(); s.demo(container, container.getSize()); s.setVisible(true); } public void demo(Container container, Dimension size) { JEditorPane editorPane = new JEditorPane(); editorPane.setEditable(false); HTMLEditorKit kit = new HTMLEditorKit(); editorPane.setEditorKit(kit); editorPane.setSize(size); editorPane.setOpaque(true); editorPane.setText("<b><font face=\"Verdana\" size=\"30\"> This is a demo text with a different font!</font></b>"); container.add(editorPane, BorderLayout.CENTER); } }
Output
- Related Questions & Answers
- How to change font size in HTML?
- How to change font size in ttk.Button?
- How to change text font for JLabel with HTML in Java?
- How can I change the font family and font size with jQuery?
- How to change text font in HTML?
- How to change Button Border in Java Swing
- How to change PowerShell ISE font Size using command?
- Change the font size of a button with CSS
- How to change the font size of textView in android?
- How to change xticks font size in a matplotlib plot?
- Can we change the Cursor with Java Swing?
- How to change JLabel font in Java
- How to change the font size of scientific notation in Matplotlib?
- How do you get the font metrics in Java Swing?
- How to change JButton font dynamically in Java?
Advertisements