user2229592
user2229592

Reputation: 71

How to add a background picture to the JMenu Screen?

so I was wondering if there is anyway to add a picture as a background for the jmenu and by that I don't mean the JMenu bar but the actual screen below it. I have looked online for a long time and can't seem to find any solution to my problem. Any help/solution would be greatly appreciated. Once again, I am trying to find a way to print a picture not on the JMenu bar, but the space that is below it.

Upvotes: 0

Views: 674

Answers (2)

camickr
camickr

Reputation: 324088

Once again, I am trying to find a way to print a picture not on the JMenu bar, but the space that is below it.

I think you mean the content pane. See Using Top Level Containers to learn some of the terminology.

If this is what you mean then check out Background Panel.

Upvotes: 2

Mr. Polywhirl
Mr. Polywhirl

Reputation: 48600

I am assuming you mean the JMenuItem? There is a post on DreamInCode.net which discusses adding an image to a JMenuItem. All you have to do is extend the JMenuItem and override its paintComponent() method.

Solution by Dogstopper:

public CustomMenuItem(){
        this.setOpaque(true);
        i = new ImageIcon(getClass().getResource("/Img/BackGround.png")).getImage();
        System.out.println(i);
}

@Override
public void paintComponent(Graphics g) {
    super.paintComponent(g);
    g.drawImage(i, 0, 0, this);

}

Upvotes: 1

Related Questions