Setting background image in JFrame

Witam,
Jak mozna ustawic tlo w postaci grafiki (png, jpg, ...) dla jFrame? Znalalem juz kilka sposobow ale one uzywaja jPanel, ktorego ja NIE moge uzyc ... niestety. Jesli nie ma takiej mozliwosci dla jFrame to moze tez byc dla jScrollPane, JComponent, Scene albo LayerWidget;)
Hi,
Is it possoble to use image as a background for jFrame? I know that it is possible to use jPanel and ser background image for jPanel, but in my project I cannot use it. Instead I can use jFrame, jScrollPane, Scene or LayerWidget.:)

In the future, Swing related questions should be posted in the Swing forum.
But there is already no need to post in the Swing forum because you already know the answer:
I know that it is possible to use jPanel and ser background image for jPanel,
If you need further help then you need to create a "Short, Self Contained, Compilable and Executable, Example Program (SSCCE)", that demonstrates the incorrect behaviour.
http://homepage1.nifty.com/algafield/sscce.html
Don't forget to use the "Code Formatting Tags", so the posted code retains its original formatting.
http://forum.java.sun.com/help.jspa?sec=formatting

Similar Messages

  • Can anyone suggest me a simple way to add a background image to JFrame ?

    I want to add a background image to JFrame in a simple way rather than overiding the paint method or paintComponent method. Just like adding an image to JButton or JLabel using two or three lines of code. Is it possible ? r there any methods for this purpose ? if so pls give the code.

    JFrame as such does not provide an option to set a background image.
    Extending JPanel, over-riding its paintComponent() and setting it as the contentPane of JFrame is one way of doing it. Though you have to do the overriding, it is not very complex though.

  • Setting background image for repeating frame in .pdf report

    Is it possible to set a background image for a repeating frame, and more specifically for a repeating frame rendered in .pdf?
    I do not see any standard property in the navigator for images of any sort and the documentation touches only on setting background images for graphs, which is not the intent in my case. I -did- add an HTML table property background="myimage.jpg" but the report is ultimately generated in .pdf format and I was not surprised to see that the image was not rendered.
    Does anyone know if setting a background image as described is even possible, and if so, how? A second but less optimum solution would be setting the image as the background for all report pages, again in .pdf.
    Many thanks.

    Hi Raj,
    Yes you can have an image in the background. Thats possible if you are using XML forms as an iview or ivew dev in WebDynpro...
    Also check this [link|regarding background color change in iview]
    Regards,
    Piyush
    Reward points if this helps!!!

  • Flex 4 Mdi canvass, how to set background image..?

    Hi.,
         Now i try to use mdi canvass  background image,how to set  background image in mdi canvass in flex 4..
    With Regards
    LinFlex-

    In the past flex 3 version, there is an attribute call <flexlib:MDICanvas  backgroundImage="@Embed(source='/imgFolder/imgFile.png')/>
    to set it. However it has problem in Flex 4 because of 'halo' and 'spark' theme library changed.
    The following is my post that still haven't found the answer.
    Dear all,
    We  have a project that doing migration from flex 3 to flex 4. We use  flexlib the latest version of
    flexlib - 2.5 - flex4.zip.
    However we  confronted problems that several of attributes that flex 4 doesn't  support:
    Constraints are listed as follows:
    1) <flexlib:MDICanvas  backgroundImage="@Embed(source='/imgFolder/imgFile.png')/>
    2)  <flexlib:MDICanvas backgroundSize="auto"/>
    3)  <mx:ApplicationControlBar barColor="#000000">
    original error message:
    ====================================================
    Description     Resource    Path    Location    Type
    The style 'backgroundImage' is  only supported by type 'flexlib.mdi.containers.MDICanvas' with the  theme(s) 'halo'.    MainView.mxml     /osss/flex_src/hk/gov/labour/osss/view    line 242    Flex Problem
    Description    Resource    Path     Location    Type
    The style 'backgroundSize' is only supported by type  'flexlib.mdi.containers.MDICanvas' with the theme(s) 'halo'.     MainView.mxml    /osss/flex_src/hk/gov/labour/osss/view    line 242     Flex Problem
    Description     Resource    Path    Location    Type
    The style 'barColor' is only  supported by type 'mx.containers.ApplicationControlBar' with the  theme(s) 'halo'.    MainView.mxml     /osss/flex_src/hk/gov/labour/osss/view    line 227    Flex Problem
    Regards,
    Man  Pak Hong, Dave
    manpakhong
    [email protected]

  • Flex4 How to set background image in Vgroup..?

    Hi.,
            I have using v flex 4 vgroup to set background image., but image was not display.. any change my code.,
    <fx:Style>
          .backgroundImage
                color:#808080;
                fontWeight:bold;
                fontSize:18;
                fontStyle:italic;
                contentBackgroundColor : #FFFFFF ;
                backgroundImage:Embed("assets/Green Apple.jpeg");
    </fx:Style>
    <s:VGroup paddingBottom="10" width="100%"  height="600" paddingTop="10"  styleName="backgroundImage">
        <s:Label text="hai hai hai">
             </s:Label>
           </s:VGroup>
    any solution to solve this....
    With Regards.,
    LinFlex-

    @Peter
    Yes! This works well now. Now I can get repeating background images directly in the code as well as in my CSS style sheets.  This looks good and helps me a lot as there are lots of occasions for me using this. I've gotten used to having repeating image backgrounds in HTML and missed that in Flex 3. This feature alone makes moving to Flex 4 worthwhile.
    This works fine for me:
    <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
                   xmlns:s="library://ns.adobe.com/flex/spark"
                   xmlns:mx="library://ns.adobe.com/flex/mx">
      <!--make a background for the whole page  -->
        <s:BorderContainer width="100%" height="100%"
             backgroundImage="@Embed('images/bkg/grey_grid.gif')"
             backgroundImageFillMode="repeat" >
      <!--make an inner area with a graphic background  -->
            <s:BitmapImage id="legalPad"
                  source="@Embed('images/bkg/legalPad.gif')"
                  fillMode="repeat"
                  left="40" top="100"
                  width="825" height="200" />
        </s:BorderContainer>
    </s:Application>
    Here are the images I used:
    grey_grid.gif
    legalPad.gif

  • Set BackGround Image

    Hi,
    i am new Developer in iphone,i want to ask very basic Question, i install iphone SDK 3.1 and using snow leopard 10.6
    how to set Background image in iphone sdk 3.1,

    Sure, search the forum, this question has been asked and answered weekly. Keywords like "background image" taken from your subject line would be a good place to start. So its really not that difficult to think up search words now is it.

  • SETTING  BACKGROUND IMAGE IN SAPSCRIPT

    HI,
    CAN U TELL  ME HOW TO SET BACKGROUND IMAGE IN SAPSCRIPT.
    REGARDS,
    SANJAY.

    Hi Sanjay,
              You can use transaction SE78 to inmport graphics to SAP.In the form painter, you can either include directly to the form using
      Edit->Graphic->Create or using the INCLUDE statement in a window.
    To use an INCLUDE stanment, goto the window script editor and use menu Include->Graphic. The include can look like this for a bitmap:
    /: BITMAP MYLOGO OBJECT GRAPHICS ID BMAP TYPE BMON

  • I need to set background image in interactive forms. How it is possible ple

    Hi,
    I need to set background image in interactive forms. How it is possible please explain it step by step.
    Regards,
    Gurprit Bhatia

    Hey Gurprit,
    All you need to do is:
    1. drag and drop the Image object from the Library -> Standard tab
    2. select the image you want to use
    3. position the image on the form where you want
    4. right click the image and say "Send to Back"
    That should be it!!
    Cheers,
    Kevin

  • How to set an image on JFrame

    i just want to know that how to set an image on JFrame.
    thanks in advance

    dear moazzam
    why are you coming here in the forms when you have very brillient java certified teacher
    who knows every thing:)
    just mail him and ask this questain from him.
    im sure you will be given a good replay
    take care !

  • Problem with Background image and JFrame

    Hi there!
    I've the following problem:
    I created a JFrame with an integrated JPanel. In this JFrame I display a background image. Therefore I've used my own contentPane:
    public class MContentPane extends JComponent{
    private Image backgroundImage = null;
    public MContentPane() {
    super();
    * Returns the background image
    * @return Background image
    public Image getBackgroundImage() {
    return backgroundImage;
    * Sets the background image
    * @param backgroundImage Background image
    public void setBackgroundImage(Image backgroundImage) {
    this.backgroundImage = backgroundImage;
    * Overrides the painting to display a background image
    protected void paintComponent(Graphics g) {
    if (isOpaque()) {
    g.setColor(getBackground());
    g.fillRect(0, 0, getWidth(), getHeight());
    if (backgroundImage != null) {
    g.drawImage(backgroundImage,0,0,this);
    super.paintComponent(g);
    Now the background image displays correct. But as soon as I click on some combobox that is placed within the integrated JPanel I see fractals of the opened combobox on the background. When I minimize
    the Frame they disappear. Sometimes though I get also some fractals when resizing the JFrame.
    It seems there is some problem with the redrawing of the background e.g. it doesn't get redrawn as often as it should be!?
    Could anyone give me some hint, on how to achieve a clear background after clicking some combobox?
    Thx in advance

    I still prefer using a border to draw a background image:
    import java.awt.*;
    import java.awt.image.*;
    import javax.swing.border.*;
    public class CentredBackgroundBorder implements Border {
        private final BufferedImage image;
        public CentredBackgroundBorder(BufferedImage image) {
            this.image = image;
        public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
            int x0 = x + (width-image.getWidth())/2;
            int y0 = y + (height-image.getHeight())/2;
            g. drawImage(image, x0, y0, null);
        public Insets getBorderInsets(Component c) {
            return new Insets(0,0,0,0);
        public boolean isBorderOpaque() {
            return true;
    }And here is a demo where I load the background image asynchronously, so that I can launch the GUI before the image is done loading. Warning: you may find the image disturbing...
    import java.awt.*;
    import java.io.*;
    import java.net.URL;
    import javax.imageio.*;
    import javax.swing.*;
    import javax.swing.border.*;
    public class BackgroundBorderExample {
        public static void main(String[] args) throws IOException {
            JFrame.setDefaultLookAndFeelDecorated(true);
            JFrame f = new JFrame("BackgroundBorderExample");
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            JTextArea area = new JTextArea(24,80);
            area.setForeground(Color.WHITE);
            area.setOpaque(false);
            area.read(new FileReader(new File("BackgroundBorderExample.java")), null);
            final JScrollPane sp = new JScrollPane(area);
            sp.setBackground(Color.BLACK);
            sp.getViewport().setOpaque(false);
            f.getContentPane().add(sp);
            f.setSize(600,400);
            f.setLocationRelativeTo(null);
            f.setVisible(true);
            String url = "http://today.java.net/jag/bio/JagHeadshot.jpg";
            final Border bkgrnd = new CentredBackgroundBorder(ImageIO.read(new URL(url)));
            Runnable r = new Runnable() {
                public void run() {
                    sp.setViewportBorder(bkgrnd);
                    sp.repaint();
            SwingUtilities.invokeLater(r);
    }

  • Problem in setting background Image to TabedPane.

    Hi Pals,
    I created a JFrame which consist of some components. The structure of the added components are given below.
    1) I added a JPanel (MainPanel) with background image in a JFrame.
    2) I added a JTabbedPane with 7 tabs in the previous JPanel (MainPanel).
    3) Each tabs in the JTabbedPane having JPanel with Background Image.
    This is my Frame Structure. but i haven't problem to run in JDK1.6,1.5. It is working perfect. But when am run in lower version like 1.3 or 1.4. The design is looking bad. The JTabbedPane overlap the (MainPanel). The background image of the (MainPanel) was hided. I set setOpaque(false) for the JTabbedPane. But it also not working. How can i solve this problem.
    By,
    Mohan

    Your problems appear to stem from your choice of layout manager(s). To get better help sooner, post a [_Short, Self Contained, Compilable and Executable, Example Program (SSCCE)_|http://mindprod.com/jgloss/sscce.html] that clearly demonstrates your problem.
    To post code, use the code tags -- [code]Your Code[/code] will display asYour CodeOr use the code button above the editing area and paste your code between the {code}{code} tags it generates.
    db

  • How to set background image in JDesktopPane

    Hi guys,
    i have a jframe linked with jdesktoppane, iand i want to set a background image to the mainframe. How??

    Search the forum: "+background +image +jdesktoppane"

  • Inserting a background image on JFrame

    I am developing an interactive system for the london 2012 olympics (Not a real one, just a project :-)) I am starting by creating my GUI layout. This is where i have started.
    import java.awt.*;        
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.border.*;
    import java.util.*;
    import java.awt.event.KeyListener;
    import java.io.*;
    import java.text.*;
    public class Assignment extends JFrame  
       private JLabel londOnJLabel;
    public Assignment()
              ImageIcon image = new ImageIcon("???.jpg");
              JLabel background = new JLabel(image);
              background.setBounds(0, 0, image.getIconWidth(), image.getIconHeight());
              getLayeredPane().add(background, new Integer(Integer.MIN_VALUE));
    private void createUserInterface()
              Container contentPane = getContentPane();
              contentPane.setLayout( null );
              londOnJLabel = new JLabel();
              londOnJLabel.setBounds( 19, 19, 875, 28 );
              londOnJLabel.setText( "LONDON 2012" );
              londOnJLabel.setFont(new Font( "Default", Font.BOLD, 36 ) );
              londOnJLabel.setHorizontalAlignment(JLabel.CENTER );
              contentPane.add( londOnJLabel );
              setTitle( "LONDON 2012" );
              setSize( 1000, 750 );         
              setVisible( true );         
    public static void main( String[] args )
          Assignment application = new Assignment();
          application.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
    }So at the moment this Just displays LONDON 2012 on my application. Now what i would like to try and do is insert a background image of the olympic rings. How would i go about doing this?
    cheers

    THFC wrote:
    sorry, when u say dont subclass JFrame, are you referring to this?
    public Assignment() ....
    No I meant don't do this: public class Assignment extends JFrameBut rather do this: do this: public class Assignment extends JPanelFor example:
    import java.awt.BorderLayout;
    import java.awt.Color;
    import java.awt.Dimension;
    import java.awt.Font;
    import java.awt.Graphics;
    import java.awt.image.BufferedImage;
    import java.io.IOException;
    import java.net.URL;
    import javax.imageio.ImageIO;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    public class Assignment2 extends JPanel
      private static final String FILE_PATH = "myImageFile.jpg"; // !! change this
      private static final String NET_URL_PATH = "http://upload.wikimedia.org/wikipedia/commons/thumb/8/82/Mooring_bollard_at_sunset%2C_Lyme_Regis.jpg/800px-Mooring_bollard_at_sunset%2C_Lyme_Regis.jpg";
      // Photo by Michael Maggs, Wikimedia Commons: http://commons.wikimedia.org/wiki/Image:Mooring_bollard_at_sunset%2C_Lyme_Regis.jpg
      private BufferedImage image = null;
      public Assignment2()
        try
          // first load the image
          //image = ImageIO.read(new File(FILE_PATH));
          image = ImageIO.read(new URL(NET_URL_PATH));
        catch (IOException e)
          e.printStackTrace();
        // then set up the JPanel.  Try to avoid using the "null" layout
        JLabel titleLabel = new JLabel("My Title Goes Here");
        titleLabel.setFont(titleLabel.getFont().deriveFont(Font.BOLD, 36));
        titleLabel.setForeground(Color.lightGray);
        JPanel titlePanel = new JPanel();
        titlePanel.setOpaque(false);
        titlePanel.add(titleLabel);
        setPreferredSize(new Dimension(800, 590));
        setLayout(new BorderLayout());
        add(titlePanel, BorderLayout.NORTH);
      @Override  // here's where I paint my background:
      protected void paintComponent(Graphics g)
        super.paintComponent(g);
        if (image != null)
          g.drawImage(image, 0, 0, this);
      private static void createAndShowUI()
        // Then I only create my JFrame when I need it.  I don't override it.
        // This way, I can use this same code in a JApplet, or a JDialog, or whatever
        JFrame frame = new JFrame("Assignment2");
        frame.getContentPane().add(new Assignment2()); // and add the JPanel to the JFrame here
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.pack();
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
      public static void main(String[] args)
        java.awt.EventQueue.invokeLater(new Runnable()
          public void run()
            createAndShowUI();
    }Edited by: Encephalopathic on May 26, 2008 4:11 PM

  • Set Background image to JScrollPane ---  Need Help!!

    Hi all;
    How can i set a Background Image to this JScrollPane?
    JLabel imageLabel;
    JScrollPane jsp = new JScrollPane(imageLabel);
    Pls need your sugessions...
    Thanking in advance
    Madumm

    I included a complete code listing of a functional example. The main problem with wha tI shared earlier was that I did it quickly in Groovy, where everything is an object. When I called layeredPane.add(xxx, 4) - the number 4 was an object - whereas in Java it is not - this called the wrong function so that the label would not appear... ok - here is the code... run this with your own image and then modify it to do what you need...
    import java.awt.Dimension;
    import java.awt.image.BufferedImage;
    import java.io.File;
    import javax.imageio.ImageIO;
    import javax.swing.ImageIcon;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JLayeredPane;
    import javax.swing.JScrollPane;
    public class BackgroundImageExample {
        public static void main(String[] args) {
            try {
                //Load Image
                String filename = "/home/dlpinto/Desktop/Screenshot.png";
                BufferedImage image = ImageIO.read(new File(filename));
                //Create Image Label
                JLabel label = new JLabel(new ImageIcon(image));
                label.setBounds(0, 0, image.getWidth(), image.getHeight());
                //Create Layered Pane
                JLayeredPane layeredPane = new JLayeredPane();
                layeredPane.setLayout(null);
                layeredPane.setPreferredSize(new Dimension(image.getWidth(), image.getHeight()));
                //Create Desired Components
                JLabel messageLabel = new JLabel("Hello World");
                messageLabel.setOpaque(true);
                messageLabel.setBounds(50, 50, 100, 100);
                //Populate Layered Pane
                layeredPane.add(label, new Integer(JLayeredPane.DEFAULT_LAYER-1));
                layeredPane.add(messageLabel, JLayeredPane.DEFAULT_LAYER);
                //Create ScrollPane
                JScrollPane sp = new JScrollPane(layeredPane);
                //Create & Display Frame
                JFrame frame = new JFrame();
                frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                frame.setSize(800, 600);
                frame.add(sp);
                frame.setVisible(true);
                System.out.println(layeredPane.getLayer(messageLabel));
                System.out.println(layeredPane.getLayer(label));
            } catch (Exception e) {
                e.printStackTrace();
    }

  • Adding background image to JFrame

    This is the code I have now. I want to add a background image to the JFrame, and it needs to be where i type the file name of the image into the program code and it loads it from my computer.
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    class GUIFrame extends JFrame implements ActionListener, KeyListener
         Display myDisplay;
         Button guess;
         Button solve;
         TextField input;
         JTextArea guessedLetters;
         MenuBar myBar;
         Menu fileMenu;
         MenuItem fileNewGame;
         MenuItem fileQuit;
         * constructor sets title of GUI window
         GUIFrame()
              super("Hangman");
              setSize(1000,600);
              guess = new Button("Guess");     
              guess.setFocusable(false);
              solve = new Button("Solve");     
              solve.setFocusable(false);
              input = new TextField(20);
              guessedLetters=new JTextArea(10,10);
              guessedLetters.setEditable(false);
              myBar=new MenuBar();
              fileMenu=new Menu("File");
              fileNewGame=new MenuItem("New Game");
              fileQuit=new MenuItem("Quit");
              myDisplay = new Display();     //make an instance of the window
              setLayout(new FlowLayout());     //How things are added to our Frame
              add(myDisplay);
              add(guess);
              add(solve);
              add(input);
              add(guessedLetters);
              setMenuBar(myBar);
              myBar.add(fileMenu);
              fileMenu.add(fileNewGame);
              fileMenu.add(fileQuit);
              addKeyListener(this);
              guess.addActionListener(this);
              solve.addActionListener(this);
              setVisible(true);     //make the frame visible
         * exectues when user presses a button.
         public void actionPerformed(ActionEvent e)
         public void keyPressed(KeyEvent e)
         public void keyReleased(KeyEvent e)
         public void keyTyped(KeyEvent e)
    }

    Look in the API under JFileChooser and Scanner to see how to get the file name. One you have it, you can load the file easily using several different methods...
    This is even easier, you can paint and image onto anything you like with this method:
    g.drawImage(image, 0, 0, null); //where g is the graphics context from the object you want to paint.
    Simple as that.
    The biggest problem you'll have with painting images onto other objects is making sure the image is loaded before you try to draw it; use ImageIO to load or add your image to a MediaTrakker after your load statement like this:
    Image im = (Image)ImageIO.read(new File("c:/myImages/myImage.jgp"));
    or
    BufferedImage bi = ImageIO.read(new File("c:/myImages/myImage.jgp"));
    or
    Image image = Toolkit.getDefaultToolkit().getImage("c:/myImages/myImage.jgp");
    MediaTracker mediaTracker = new MediaTracker(jf);
    mediaTracker.addImage(image, 0);
    mediaTracker.waitForID(0);
    BTW: what this means it that you can paint right onto the graphics content of the JFrame and not have to worry about any other containers if you want.
    If you expect the image to last more than just a flash, then you also need to override your paintComponents(Grahics) method to paint your graphics to your screen.

Maybe you are looking for

  • SAP MII 14.0 unable to open workbench

    Hello Experts, I am facing issue while opening workbench . The exception thrown is as below : "com.sun.deploy.net.JARSigningException: Found unsigned entry in resource: http://[sever]:[port]/XMII/CMSLogicEditor/xalan.jar" I am using SAP MII 14.0 SP5

  • Ipod producing stereo sound in one headphone

    so today i semi dropped my ipod and then i had no sound from headphones, then i hit it and the sound came back in one ear and not the other.....is my ipod messed? or just crap headphones? any ideas on it?

  • Cisco ACS with External DB - EAP-TLS

    Hi Guys, I understand how the EAP-TLS exchange works (I think), but If I have a client (wireless or wired) that is using EAP-TLS with an ACS, can I confirm the following. Let say both user and computer certs are employed: 1. Both Client and ACS perfo

  • MPB 17" Student backpack

    Ok, I just got my MBP 17" and I leave for college in August. I need a laptop backpack. But, I need one that lets me carry a couple books as well. I've looked on the site and a couple reviews say most of them are hard to fit the MBP in without pulling

  • How to add minutes to date in java

    I have date in string variable, i have to add/subtract minutes from it, please adivce , how i could do in java 1.5 sample data String olddate = "12/16/2010 4:58:29 PM" String minutes1 = "300" i would like to get value as below for above data String n