This illustrates setting background image to JMenuBar. For this we need to paint an background image on JMenuBar. 1 main step is far from background image.
paintComponent(Graphics g): Takes java.awt.Graphics as parameter. This contains drawImage() method which takes java.awt.Image object, x,y axes and ImageObserver object. paint() is not used here because, if we use this, i could not see the Menu.
g.drawImage(Toolkit.getDefaultToolkit().getImage("F:/Wallpapers/violetpink.png"),0,0,this): Method of java.awt.Graphics class. java.awt.Toolkit is a class containing a static method getDefaultToolkit() which returns the object of that class only (java.awt.Toolkit). This class contains getImage() method which takes the path of the image file and returns the java.awt.Image object. My background image is located in F:\Wallpapers. You can notice / instead of \ this is because / is equal to \\ in Windows and similar operating systems. Next, 0,0 are the x,y co ordinates respectively. Try changing them, you'll notice the change. this represents current object which acts as ImageObserver.
In this way, we can set background image to JMenuBar easily in single step.
This blog contains Java Tutorials, Code Samples,demonstrating several concepts in Java. All the code samples are well tested by a team of experts and hence there will be no programmatical errors. We are seamlessly thriving in making the tutorials easier for beginners.
Gowtham Gutha was a software and technology enthusiast. He is a 12th grade student and a part time blogger with extreme love in Java programming.Follow him on Google+ and Twitter or befriend him on Facebook and also on CodeProject
0 comments:
Post a Comment