Question

I would like to know if it's possible to set an image as background for a jmenubar+jtoolbar (not only for one of theym, not one for each of theym But on for BOTH) ...

Anyone's got an idea ?? How should I do that if it's possible ?

Thanks !

Here an image to explain : enter image description here

Solved :: I used two images (cutted to the right size to suite my jmenubar+jtoolbar) and added these to the object's declarations as overrides and it works great ! Here is a piece of code :

    ///////////////////////////////
    JToolBar toolBar = new JToolBar(){
        @Override
        protected void paintComponent(Graphics g){

            Image photo = getToolkit().getImage("src/MainFrame/Images/xtremeCalliBottom.png");
            super.paintComponent(g) ; 
            int x=(mainFrame.getWidth()-200), y=0 ; 
            if(photo != null) 
                g.drawImage (photo, x, y, this);
        }
    };

    // ............

    //========== Menu Bar
    jMenuBar = new JMenuBar(){
        @Override
        protected void paintComponent(Graphics g){

            Image photo = getToolkit().getImage("src/MainFrame/Images/xtremeCalliTop.png");
            super.paintComponent(g) ; 
            int x=(mainFrame.getWidth()-200), y=0 ; 
            if(photo != null) 
                g.drawImage (photo, x, y, this);
        }
    };

     // ................


    jMenuBar.setPreferredSize(new Dimension(100, 25));
    toolBar.setPreferredSize(new Dimension(100,40));
Was it helpful?

Solution

Sure, but you'll have to override them separately. You'll also need to keep some global variable (or one that you can pass between the two) so that they can know how big each of them are.

You'll need to override paintComponent() or add your own UI delegate to do the painting. You can load the image and paint just the top portion (or relative percentage) on the menubar, then paint just the bottom portion or relative percentage on the toolbar.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top