
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
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
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
Advertisements