我正在尝试创建一个Java应用程序。java应用程序应该有一个带有流布局的菜单栏。
现在,在这个菜单栏中,我想介绍三个按钮:
我想利用这些按钮中的图像。就像Word关联了一张白纸的图像来启动一个新的项目,一个目录来打开一个保存的项目,一个软盘来保存一个项目。
请用Java怎么做?
编辑
我试过这个代码:
UIManager.getIcon("FileView.directoryIcon");
UIManager.getIcon("FileView.fileIcon");
UIManager.getIcon("FileView.floppyDriveIcon");发布于 2012-11-14 10:50:03
我不确定Java中是否有标准的映像,我相信没有。
但是你可以捕捉这些图片或者下载一个包。
然后您只需使用来自here的代码
JButton button = new JButton();
try {
Image img = ImageIO.read(getClass().getResource("resources/water.bmp"));
button.setIcon(new ImageIcon(img));
} catch (IOException ex) {
}发布于 2012-11-14 10:55:34
尝试:
ImageIcon icon = new ImageIcon("Path to the image.format");
JButton btnOne = new JButton();
btnOne.setBackground(icon);其中的路径是你想要的背景的诱惑图像的位置。
https://stackoverflow.com/questions/13377024
复制相似问题