Here is my class that tries to use a JRootPane to attach an SVG image as a background image and then add JLabels on top. It doesn't work and just displays the SVG image. If I add the glassPane to the JFrame's contentPane then all I get is a grey nothingness. Why won't the glassPane display the labels? Where am I going wrong? All I want is a set of JLabels with an SVG image in the background (not the background of the labels but behind the labels so the labels are on top of this image).

 

public class TestBackgroundSVG

{

    public static void main(String args[])

    {

        JFrame f = new JFrame("Test");

        Container c = f.getContentPane();

        JLabel lab1 = new JLabel("label1");

        JLabel lab2 = new JLabel("label2");

       

        JSVGCanvas canvas = new JSVGCanvas();

        canvas.setURI("http://localhost:8081/SVGImages/Background.svg");

       

        JRootPane rootPane = new JRootPane();

        rootPane.setContentPane(canvas);

        rootPane.setGlassPane(new JPanel());

 

        JPanel glassPane = (JPanel)rootPane.getGlassPane();

        glassPane.add(lab1);

        glassPane.add(lab2);

        glassPane.setOpaque(false);

 

        c.add(rootPane);

 

        f.addWindowListener(new WindowAdapter(){

            public void windowClosing(WindowEvent e){

                System.exit(0);

            }

        });

       

        f.pack();

        f.setSize(200,200);

        f.setVisible(true);

    }

}

 

any help would be great

cheers

Claire :)

>Reply-To: <[EMAIL PROTECTED]>

>To: "'Batik Users'" <[EMAIL PROTECTED]>
>Subject: RE: AW: question on JSVGCanvas
>Date: Thu, 13 Mar 2003 09:24:11 +0100
>
>Hi Claire,
>By looking at the Java documentation of JRootPane, you can use the method
>setGlassPane where you can pass in a component you would like to act as the
>glasspane.
>If you look at the class Component, you can see that a Container is also a
>Component, so you could do this: rootPane.setGlassPane( new JPanel() );
>and then when you call getGlassPane, you can cast it to the JPanel: JPanel
>glassPanel = (JPanel) rootPane.getGlassPane(); and then you can add you're
>labels etc.
>Hope this helps,
>Harm
>
>-----Original Message-----
>From: Claire Wall [mailto:[EMAIL PROTECTED]
>Sent: woensdag 12 maart 2003 22:38
>To: [EMAIL PROTECTED]
>Subject: Re: AW: question on JSVGCanvas
>
>
>
>how do we add JLabels to the glassPane?
>
>As I understand it, the JRootPane object contains a component glassPane.
>However the glassPane does not allow me to directly add a java component to
>itself. The only add method it has takes a PopupMenu object as its parameter
>and this is no good.
>
>I know from your reply that it is  possible to add JLabels (or any component
>for that matter) to the glassPane but as I have never used JRootPane before
>can't seem to see how to do this.
>
>Any help would be good.
>
>Cheers
>
>Claire
>
>
> >From: "Lolling, Jan"
> >Reply-To: "Batik Users"
> >To: [EMAIL PROTECTED]
> >Subject: AW: question on JSVGCanvas
> >Date: Tue, 11 Mar 2003 18:25:18 +0100
> >
> >A possible architecture could be:
> >Use a JRootPane and add JSVGCanvas to the contentPane
> >Add your labels to the glassPane und make shure that your glassPane is not
>opaque.
> >
> >Be aware that JSVGCanvas resize his dimension if you load an SVG image zo
>fit the image ins the whole size. You have to adapt your svg code to create
>the correct image dimension.
> >
> >Jan
> >
> >
> >-----Ursprungliche Nachricht-----
> >Von: Claire WALL [mailto:[EMAIL PROTECTED]
> >Gesendet: Dienstag, 11. Marz 2003 18:15
> >An: [EMAIL PROTECTED]
> >Betreff: question on JSVGCanvas
> >
> >
> >Hi,
> >
> >I want to have a JPanel with an SVG image as the background.
> >The JPanel will contain JLabels. How would I do this?
> >
> >Is it possible to add JLabels onto an JSVGCanvas? Or is there a
> >way to set an SVG image as a background with JLabels on top?
> >
> >
> >Claire
> >
> >---------------------------------------------------------------------
> >To unsubscribe, e-mail: [EMAIL PROTECTED]
> >For additional commands, e-mail: [EMAIL PROTECTED]
> >
> >---------------------------------------------------------------------
> >To unsubscribe, e-mail: [EMAIL PROTECTED]
> >For additional commands, e-mail: [EMAIL PROTECTED]
> >
>
> _____
>
>Send instant messages for free with MSN Messenger. Click here to download it
>now! ---------------------------------------------------------------------
>To unsubscribe, e-mail: [EMAIL PROTECTED] For
>additional commands, e-mail: [EMAIL PROTECTED]
>


Message your friends in real time - and for free. Get MSN Messenger today! --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to