请问,高手 怎么去掉java工具栏按钮 的边框?

2024-12-31 08:07:54
推荐回答(1个)
回答1:

设置每一个按钮的边框就可以了。比如:import javax.swing.ImageIcon;import javax.swing.JButton;import javax.swing.JFrame;import javax.swing.JToolBar;public class Test extends JFrame {private JToolBar toolbar = new JToolBar(Test ToolBar);private JButton button1 = new JButton(new ImageIcon(c:\\1.png));private JButton button2 = new JButton(new ImageIcon(c:\\2.png));private JButton button3 = new JButton(new ImageIcon(c:\\3.png));private JButton button4 = new JButton(new ImageIcon(c:\\4.png));private JButton button5 = new JButton(new ImageIcon(c:\\5.png));private Test() {super(Test);this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);// 设定button1的边框不填充button1.setBorderPainted(false);// 设定button2的边框不填充button2.setBorderPainted(false);// 设定button3的边框不填充button3.setBorderPainted(false);// 设定button4的边框填充button4.setBorderPainted(true);// 设定button5的边框填充button5.setBorderPainted(true);toolbar.add(button1);toolbar.add(button2);toolbar.add(button3);toolbar.add(button4);toolbar.add(button5);this.getContentPane().add(toolbar);this.pack();}public static final void main(String[] args) {Test t = new Test();t.setVisible(true);}}运行效果图: