- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- 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 can we implement the HTML text of JButton in Java?
A JButton is a subclass of AbstractButton and it is an important component in the Java Swing hierarchy. A JButton can be used mostly in the login based applications. A JButton can generate an ActionListener interface when we trying to press or click a button. A JButton has a text or icon or both text and icon, we can also implement bold, italic text using HTML tags.
Example
import java.awt.*; import javax.swing.*; public class JButtonHtmlTextTest extends JFrame { private JButton jbutton1, jbutton2; public JButtonHtmlTextTest() { setTitle("JButtonHtmlText Test"); jbutton1 = new JButton("Normal Button"); jbutton1.setHorizontalAlignment(SwingConstants.CENTER); add(jbutton1, BorderLayout.WEST); jbutton2 = new JButton("HTML Text Button"); jbutton2.setHorizontalAlignment(SwingConstants.CENTER); add(jbutton2, BorderLayout.EAST); setSize(375, 250); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setLocationRelativeTo(null); setVisible(true); } public static void main(String[] args) { new JButtonHtmlTextTest(); } }
Output
- Related Articles
- How can we change the JButton text dynamically in Java?\n
- How can we set the margin to a JButton in Java?
- How can we implement a long text of the JOptionPane message dialog in Java?
- How can we apply different borders to JButton in Java?
- How can we implement a moving text using a JLabel in Java?
- How can we set the shortcut key to a JButton in Java?
- How can we add/insert a JButton to JTable cell in Java?
- How can we implement a JLabel text with different color and font in Java?
- How can we implement line wrap and word wrap text inside a JTextArea in Java?
- How can we implement a JToggleButton in Java?
- How can we implement editable JComboBox in Java?
- How can we implement transparent JDialog in Java?
- How to implement a rollover effect for a JButton in Java?
- How can we implement the SubmissionPublisher class in Java 9?
- How can we implement the Subscriber interface in Java 9?

Advertisements