发布网友 发布时间:2022-07-02 20:57
共1个回答
热心网友 时间:2023-10-29 15:12
设置每一个按钮的边框就可以了。比如: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);}}运行效果图: