1

I am trying to make a Java application. The java application is supposed to have a menu bar with a flow layout.

Now, in this menu bar, I want to introduce three buttons:

  1. To start a new project
  2. To open a saved project
  3. To save a project

I want to make use of images in these buttons. Much like Word associated an image of a blank sheet of paper to start a new project, a directory to open a saved project, and a diskette to save a project.

How can this be done in Java please?

Edit

I tried this code:

UIManager.getIcon("FileView.directoryIcon");
UIManager.getIcon("FileView.fileIcon");
UIManager.getIcon("FileView.floppyDriveIcon");
kleopatra
  • 51,061
  • 28
  • 99
  • 211
Matthew
  • 4,477
  • 21
  • 70
  • 93
  • I am new to Java GUI programming. I tried to assign an image to a JButton, and was successful. However, I can't seem to find the images I want. – Matthew Nov 14 '12 at 10:37
  • > However, I can't seem to find the images I want. How does this relate to Java? – Nikolay Kuznetsov Nov 14 '12 at 10:39
  • I can't show you an image because I don't have that privilege as yet. To give you an idea, look at the icons that Microsoft Word 2003 uses in order to let the user start a new document, open a document and save an existing document. I want to use those precise three icons but don't know if they are available using the method I used. – Matthew Nov 14 '12 at 10:40
  • Ok, I understand now what you trying do. How about capturing those images into png files and then loading from them? – Nikolay Kuznetsov Nov 14 '12 at 10:42
  • Thanks. Good idea. I thought that Java would provide them in-built. Thanks again :) – Matthew Nov 14 '12 at 10:45

2 Answers2

2

I am not sure if there standard images available in Java, I believe there is not.

But you can capture those images or download a pack.

Then you just use the code from here

JButton button = new JButton();


  try {
    Image img = ImageIO.read(getClass().getResource("resources/water.bmp"));
    button.setIcon(new ImageIcon(img));
  } catch (IOException ex) {
  }
Community
  • 1
  • 1
Nikolay Kuznetsov
  • 9,467
  • 12
  • 55
  • 101
1

Try:

ImageIcon icon = new ImageIcon("Path to the image.format");
JButton btnOne = new JButton();
btnOne.setBackground(icon);

Where the path is the location of capured images of what you want as background.

R. Gulbrandsen
  • 3,648
  • 1
  • 22
  • 35