public void createTool() {
toolBar = new JToolBar();
toolBar.setFloatable(false);
JButton btn_1 = new JButton(new ImageIcon("O://Eclipse-workspace//Micaps_Main//img//0.jpg"));
btn_1.setToolTipText("新建交互层");
toolBar.add(btn_1);
c.add(toolBar);
}
//代码运行后,没有出现工具栏
public void createTool() {
toolBar = new JToolBar();
toolBar.setFloatable(false);
Icon image = new ImageIcon("O:\\Eclipse-workspace\\Micaps_Main\\img\\0.png");
JButton btn_1 = new JButton(image);
btn_1.setToolTipText("新建交互层");
toolBar.add(btn_1);
c.add(toolBar);
}
修改之后
public void createTool() {
Icon image = new ImageIcon("O:\\Eclipse-workspace\\Micaps_Main\\img\\新建.png");
JButton btn_1 = new JButton(image);
toolBar.setBounds(0,20, this.getSize().width, 25);
btn_1.setToolTipText("新建交互层");
toolBar.add(btn_1);
c.add(toolBar);
c.setLayout(null);
}
05-24
7065
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)