How to change Button Border in Java Swing
对于按钮边框,请使用Java中的createLineBorder()方法,该方法还可以设置边框的颜色:
1 2 | JButton button = new JButton("Demo Button!"); Border border = BorderFactory.createLineBorder(Color.BLUE); |
以下是在Java中更改按钮边框的示例:
例
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | import java.awt.BorderLayout; import java.awt.Color; import java.awt.Container; import javax.swing.BorderFactory; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.border.Border; public class SwingDemo { public static void main(String args[]) { JFrame frame = new JFrame("Button Border"); Container container = frame.getContentPane(); JButton button = new JButton("Demo Button!"); Border border = BorderFactory.createLineBorder(Color.BLUE); button.setBorder(border); container.add(button, BorderLayout.CENTER); frame.setSize(550, 300); frame.setVisible(true); } } |
输出量