在JButton中用Html220525
测试代码👇
package buttonJButton;
import java.awt.Frame;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.JButton;
public class 在JButton中用Html220525 {
public static void main(String...arguments) {
Frame frame = new Frame("在JButton中用Html220525");
frame.addWindowListener(new WindowAdapter() {
@Override public void windowClosing(WindowEvent event) {System.exit(0);}
});
frame.setBounds(100,50,1600,900);
JButton jbt = new JButton("""
<html>
<div style="font-size:25px;">这是一个Button</div>
<div style="position:relative;">
<button style="font-size:30px; position:absolute; left:80px; top:80px;" >这是JButton中的HtmlButton , 看来不支持button标签</button>
</div>
</html>
""");
frame.add(jbt);
frame.setVisible(true);
}
}
效果👇
不支持button标签, 不支持position
去掉JButton为焦点时的虚线框, 用setFocusPainted(false);
setFocusPainted(false);