Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<ul> <li><p>AFAIK for Buttons JComponents and JTabbedPane only by using Html</p></li> <li><p>or to override <a href="https://stackoverflow.com/a/5755124/714968">BasicButtonUI(code example about localized MetalLookAndFeel)</a></p></li> </ul> <p><img src="https://i.stack.imgur.com/8rWVj.jpg" alt="enter image description here"> . . . . . .<img src="https://i.stack.imgur.com/hN2u8.jpg" alt="enter image description here"></p> <pre><code>import java.awt.GridLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.SwingUtilities; public class HtmlAndJButton { final String buttonText = " Whatever words, &lt;br&gt; but nothing wise"; final String buttonText1 = " Whatever words, &lt;br&gt; but nothing wise, " + "&lt;br&gt; plus 1st. line, "; final String buttonText2 = " Whatever words, &lt;br&gt; but nothing wise, " + "&lt;br&gt; plus 1st. line, &lt;br&gt; plus 2nd. line,"; private JButton btn1 = new JButton("Toggle"); private JButton button = new JButton(buttonText); private JButton button1 = new JButton("Toggle"); private JButton button2 = new JButton("Toggle"); public HtmlAndJButton() { btn1.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { button.setText("&lt;html&gt;&lt;font color=" + (button.isEnabled() ? "blue" : "red") + "&gt;" + buttonText + "&lt;/font&gt;&lt;/html&gt;"); button.setEnabled(!button.isEnabled()); button1.setText("&lt;html&gt;&lt;font color=" + (button1.isEnabled() ? "red" : "green") + "&gt;" + buttonText1 + "&lt;/font&gt;&lt;/html&gt;"); button1.setEnabled(!button1.isEnabled()); button2.setText("&lt;html&gt;&lt;font color=" + (button2.isEnabled() ? "green" : "yellow") + "&gt;" + buttonText2 + "&lt;/font&gt;&lt;/html&gt;"); button2.setEnabled(!button2.isEnabled()); } }); button.setText("&lt;html&gt;&lt;font color=red&gt;" + buttonText + "&lt;/font&gt;&lt;/html&gt;"); button1.setText("&lt;html&gt;&lt;font color=green&gt;" + buttonText1 + "&lt;/font&gt;&lt;/html&gt;"); button2.setText("&lt;html&gt;&lt;font color=yellow&gt;" + buttonText2 + "&lt;/font&gt;&lt;/html&gt;"); JFrame f = new JFrame("ButtonTest"); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setLayout(new GridLayout(2, 2)); f.add(button); f.add(button1); f.add(button2); f.add(btn1); f.pack(); f.setLocationRelativeTo(null); f.setVisible(true); } public static void main(String[] args) { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { HtmlAndJButton t = new HtmlAndJButton(); } }); } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload