Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / June 2005

Tip: Looking for answers? Try searching our database.

Jtoolbar and JToolmenu

Thread view: 
Pedro Silva - 16 Jun 2005 23:14 GMT
Hi all :

first of all ... sorry for the noob question !!!

Is there a way to put an background image in the Jtoolbar and JToolmenu?

I am new in java but old (jurassic old) in VB and VFP.
There, in the activeX, sometimes I can chose a background image for the
toolbars.

thanks
Bill Tschumy - 16 Jun 2005 23:31 GMT
> Hi all :
>
[quoted text clipped - 7 lines]
>
> thanks

You will have to subclass JToolbar and in the paintComponent() method,
display the image.

Something like:

Image myImage =  [load image from somewhere];

public void paintComponent (Graphics g)
{
   g.drawImage(myImage, 0, 0, this);
}

Not sure what you mean by JToolmenu.  Do you mean JMenu or JMenuBar?  If so,
you can try the same technique with them.
Signature

Bill Tschumy
Otherwise -- Austin, TX
http://www.otherwise.com

Pedro Silva - 17 Jun 2005 12:47 GMT
Yes ... thats it :-)
(JMenu)

As you see ... noob guy in Java :-S

Thanks ;-)

>>Hi all :
>>
[quoted text clipped - 22 lines]
> Not sure what you mean by JToolmenu.  Do you mean JMenu or JMenuBar?  If so,
> you can try the same technique with them.
Pedro Silva - 17 Jun 2005 16:01 GMT
do you mean like this ?
It just puts a black stripe in 0,0 and the JMenuBar under it :-(

what am I doing wrong ?

*******************************************
import javax.swing.* ;
import java.awt.* ;

public class MyToolbar extends JMenuBar {

    Image myImage2 ;

    public MyToolbar() {

    ImageIcon("/home/pedro/JavaApplication1/FundoMenu2.bmp") ;
        Image myImage2 =
Toolkit.getDefaultToolkit().getImage("/home/pedro/JavaApplication1/FundoMenu2.jpg")
;
    }

public void paintComponent (Graphics g)
{
    if(myImage2!= null)
    {
        g.drawImage(myImage2, 0, 0, this);
    }
}

}
*********************************************

>>Hi all :
>>
[quoted text clipped - 22 lines]
> Not sure what you mean by JToolmenu.  Do you mean JMenu or JMenuBar?  If so,
> you can try the same technique with them.
Bill Tschumy - 17 Jun 2005 20:43 GMT
> do you mean like this ?
> It just puts a black stripe in 0,0 and the JMenuBar under it :-(
[quoted text clipped - 13 lines]
>     ImageIcon("/home/pedro/JavaApplication1/FundoMenu2.bmp") ;
>          Image myImage2 =

Toolkit.getDefaultToolkit().getImage("/home/pedro/JavaApplication1/FundoMenu2.

> jpg")
> ;
[quoted text clipped - 38 lines]
>> so,
>> you can try the same technique with them.

I suspect the problem is that the image isn't fully loaded.  In Java, you
have to go through the extra step of waiting for the image to fully load
using the MediaTracker (a poor design decision IMO).  Something like:

                                                            // The this argument is the component that will use the image
               MediaTracker mt = new MediaTracker(this);  
               try
               {
                   mt.addImage(image, 0);
                   mt.waitForID(0);
               }
               catch (InterruptedException e)
               {
               }

Now you can use the image for drawing.

Of course, it is also possible that you can't draw a background image for
JMenuBar.  I have only done it for JPanels.

Signature

Bill Tschumy
Otherwise -- Austin, TX
http://www.otherwise.com



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.