JMenu with images

Z

zero

http://www.cs.cf.ac.uk/Dave/HCI/HCI_Handout_CALLER/menu.gif

In this picture we see a JMenu with images.

How can I create the same menu with

New
SaveAs
Properties
Exit

Start in y axis of "O" from "Open"?

Easiest would be to have a transparent gif image the same size of the other
icons and use that for the JMenuItems that don't have an icon.

I think you can do the same by using Swing "padding" classes such as
HorizontalGlue. I'm not sure though. And even if it is possible, I don't
recommend it. It'll be a lot of code for what can be done with one or two
lines if you just add a transparent gif image.
 
T

Thomas Fritsch

zero said:
Easiest would be to have a transparent gif image the same size of the
other
icons and use that for the JMenuItems that don't have an icon.

As an alternative you can create a transparent icon with the following
class:

public class BlankIcon implements Icon {
public int getIconHeight() { return 24; }
public int getIconWidth() { return 24; }
public void paintIcon(Component c, Graphics g, int x, int y) {
/*nothing*/ }
}
 
Z

zero

As an alternative you can create a transparent icon with the following
class:

public class BlankIcon implements Icon {
public int getIconHeight() { return 24; }
public int getIconWidth() { return 24; }
public void paintIcon(Component c, Graphics g, int x, int y) {
/*nothing*/ }
}

Interesting idea. Have you tested this with both opaque and non-opaque
components?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,679
Members
48,796
Latest member
Greg L.

Latest Threads

Top