Images in JFrame

Hi. I need to put an image over a JFrame, I browse a lot of sites but I did not found anything useful. Someone know how to do this?
Regards.

You cannot place the image directly on the JFrame's rootpane
Try the following
JLabel imageLabel = new JLabel(new ImageIcon("test.gif"));Then add this label to your frame.

Similar Messages

  • Problem with display an image on JFrame in Java 6

    I'm trying to display an image on JFrame in this way:
    1.) I'm creating a variable in the class:
        private Image imgSpeaker = null;2.) I'm overiting the paint method:
    public void paint(Graphics g) {
            super.paint(g);   
            g.drawImage(imgSpeaker, 330, 230, null);  
        }3.) In the constructor I'm using this code:
       imgSpeaker = Toolkit.getDefaultToolkit().getImage("D:\\speaker.gif");
            MediaTracker trop = new MediaTracker(this);
            trop.addImage(imgSpeaker,0);
            try {
                trop.waitForID(0);    // waiting untill downloading progress will be complite
            } catch (Exception e) {
                System.err.println(e);
            }        The Image will be displayed on form, but if I catch the window and move it (for example: down as possible)
    the image is not refreshed (repainted). What I'm doing wrong? I've been used this solution in Java 5 and everything
    works perfectly. Any of described methods aren't depricated... Anyone can help me?

    Thanks for your code, I've been tryed to apply your solution (with create a Buffered Image), but it still not working correctly. Firstly, the image isn't loading, and secondly the basic problem is not give in. Why have you been using "bg2d.draw(img, x, y, w, h, frame);" not in the paint method?
    I'm use "Free Design" layout. Below I put on completly code from Netbeans.
    import java.awt.Graphics;
    import java.awt.Image;
    import java.awt.MediaTracker;
    import java.awt.image.BufferedImage;
    public class ImageTest extends javax.swing.JFrame {
        private Image imgSpeaker = null;
        private BufferedImage bi = null;
        private MediaTracker trop = null;
        public ImageTest() { 
                initComponents();
                trop = new java.awt.MediaTracker(this);
                imgSpeaker = java.awt.Toolkit.getDefaultToolkit().getImage("D:\\speaker.gif");
                try {
                    trop.addImage(imgSpeaker, 0);
                    trop.waitForID(0);
                } catch (java.lang.Exception e) {
                    java.lang.System.err.println(e);
                bi = new java.awt.image.BufferedImage(100, 100, java.awt.image.BufferedImage.TYPE_INT_RGB);
                java.awt.Graphics2D bg2d = (java.awt.Graphics2D) bi.createGraphics();
                trop.addImage(bi, 1);
    //            java.io.File f = new java.io.File("D:\\speaker.gif");
    //            try {
    //                bi = javax.imageio.ImageIO.read(f);
    //            } catch (IOException e) {
    //               java.lang.System.err.println(e);
        public void paint(Graphics g) {
    //      super.paint(g);
           try {                                                   
                trop.waitForAll();                                 
            } catch (Exception e) {
                System.err.println(e);
            g.drawImage(bi, 50, 100, imgSpeaker.getHeight(this), imgSpeaker.getHeight(this), this);
        // <editor-fold defaultstate="collapsed" desc=" Generated Code ">
        private void initComponents() {
            jButton1 = new javax.swing.JButton();
            setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
            jButton1.setText("jButton1");
            javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
            getContentPane().setLayout(layout);
            layout.setHorizontalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                    .addContainerGap(283, Short.MAX_VALUE)
                    .addComponent(jButton1)
                    .addGap(44, 44, 44))
            layout.setVerticalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                    .addContainerGap(252, Short.MAX_VALUE)
                    .addComponent(jButton1)
                    .addGap(25, 25, 25))
            pack();
        }// </editor-fold>
        public static void main(String args[]) {
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    new ImageTest().setVisible(true);
        private javax.swing.JButton jButton1;
    }

  • Inserting an image to Jframe and save it ,  in SQL database

    Hai guys,
    I just wanna know about the inserting image in to a Jframe (in netBeans) it will be a grate help if you tell me the way to call a image to Jframe through a Button click and save the image in MySQl database.
    Is anyone has a idea about this task, please tell me
    Thanks,

    Image class should work to get the data, then add it to a Canvas object, then you can save the bytes from the Image into an SQL statement through JDBC.
    The implementation details will vary based on which approch and database you select.

  • GIF images in JFrame

    hi all, i'm trying to put a gif image in JFrame. The problem is the gif images gets flickering(fluctuation) while it is placed in a frame. i had also placed some labels near the image and all of them gets disturbed becoz of this gif file in frame. plz tel me a solution.
    Thanks .
    //MY CODE
    //~~~~~~~~~~
    import java.awt.*;
    import java.awt.Color;
    import java.awt.event.*;
    import javax.swing.*;
    class Label_ON_G extends JFrame// implements MouseListener,MouseMotionListener
      private Image image;
      JLabel label1;
      JButton button1;
      Dimension dimension=Toolkit.getDefaultToolkit().getScreenSize();
      public Label_ON_G()
           super("Display image example");
           getContentPane().setBackground(Color.white);
           getContentPane().setSize(dimension);
        setResizable(true);
        getContentPane().setLayout(null);
         Toolkit tk = Toolkit.getDefaultToolkit ();
         image = tk.getImage ("singlearea.gif");
        label1= new JLabel("RADHA");
        label1.setBounds(120,110,80,30);
        label1.setEnabled(false);
        add(label1);
        button1= new JButton("VIEW LABEL");
        button1.addActionListener(new ActionListener(){
             public void actionPerformed(ActionEvent ae)
              label1.setEnabled(true);
             System.out.println("ActionPerformed");
        button1.setBounds(600,600,100,30);
        add(button1);
        setVisible(true);
        show();
    public void paint (Graphics g)
      g.drawImage(image, 100, 100, this);
      public static void main (String[] args)
      {     new Label_ON_G();     }
    }

    There is no need to do custom painting to display an image.
    [url http://java.sun.com/docs/books/tutorial/uiswing/components/label.html]How to Use Labels
    Unless you know what you are doing, never override the paint() method of the JFrame. There is no reason to do this.
    If you need to do custom painting then you override the paintComponent() method of a component that extends JComponent.

  • Inserting image to jFrame and save it in a sql database

    Hai guys, I have a problem in inseting a image in jfame and save it in database (my sql)
    does any one have an idea about this task reply me pls
    thanks
    bay !

    Use BLOB (Binary Large Object) to save your image to a database.
    As far as displaying a image on Jframe, search the forum.

  • How to display image in JFrame

    i am comfortable with displaying an image in applets ,but i am not able to display image in JFrames
    i used Image img=getImage(getDocumentBase(),"sample.jpg");its displaying an error cant find symbol getDocumentBase()

    It is a method of Applet. If you have a question of what methods
    are available in a given class, the very first thing you should do is check the API:
    http://java.sun.com/javase/6/docs/api/
    Take a look at the code in reply #2: http://forum.java.sun.com/thread.jspa?threadID=5152350

  • Add image to JFrame title?

    Hi, everybody
    Can i add a image to JFrame title by side right system menu?
    Thanks for your advice

    Prior to JDK 1.4 you can't without using native code.
    This is because the frame's title is displayed by the native windowing system.
    All you could do is use JWindow instead of JFrame and draw the decorations yourself completely. This can have other disadvantages besides the amount of work, like for example the window not showing up in the task bar on Windows systems.
    Using Merlin (1.4, currently in Beta) you can tell the frame to manage the title from the Java side using JFrame.setLookAndFeelDecorated(true).
    In that case the title bar is a subclass of JPanel (class name is called something like BasicTitlePaneUI, look it up yourself) and you could add anything you like to it.
    Hope it helps, Stephen

  • How to place an image in JFrame

    hello
    i want to know how to place a image on JFrame
    i am not using any layout..
    pls help..

    Hi...
    To do this, u can look to tweak the paintComponent() method . All u have to do is create a JPanel subclass and override the paintComponent method to draw the image. then set it as the frame's content pane. that is because you work only on the content pane in swing. that should help.
    Source for ImagePanel :
    <code>
    package com.rsramanujam.help;
    import javax.swing.*;
    import java.awt.*;
    import java.awt.image.*;
    public class ImagePanel extends JPanel
         Image backImage = null;
         public ImagePanel(Image backImage)
              try
                   this.backImage = backImage;
              catch(Exception e)
                   System.out.println("Could not get Image");
         public void paintComponent(Graphics g)
              Graphics innerG = g.create();
              if(backImage == null)
                   innerG.setColor(new Color(0xffccccff));
                   innerG.fill3DRect(0,0,getSize().width,getSize().height,true);
              else
                   innerG.drawImage(backImage,0,0,getSize().width,getSize().height,this);
         public void setBackImage(String path)
              ImageIcon ic = new ImageIcon(path);
              this.backImage = ic.getImage();
              repaint();
    </code>
    U can see a working example at http://www.geocities.com/ramanujam_off/java.
    There , download the app called RamHelp. It comes with a GUI that uses panels with Background Images.
    Regards,
    Ramanujam

  • 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.

  • 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);
    }

  • Display image in JFrame

    I am looking for a way to display an image in a jframe. I want to avoid wrapping it into a container..such as a JPanel, JLabel..ect. Does anyone know a way? I seen in the API there is a Graphics function drawImage but I can not get it to work, and tried using the paintIcon function from the ImageIcon class but that doesnt work either. Any one that can help I would much appreciate it. Thanks
    import javax.swing.*;
    import java.awt.*;
    class displayImage extends JFrame{
    // user's screen width
    private int screenWidth;
    // user's screen height
    private int screenHeight;
    ImageIcon im;
    Image image;
    public displayImage (){
    im = new ImageIcon( "<filename>" );
    image = Toolkit.getDefaultToolkit().getImage("<filename>"");
    screenWidth = (int)Toolkit.getDefaultToolkit().getScreenSize().getWidth();
    screenHeight = (int)Toolkit.getDefaultToolkit().getScreenSize().getHeight();
    resizeGUI ();
    setVisible(true);
    validate();
    public void paint(Graphics g) {
    im.paintIcon(this,g,180,0);
    g.drawImage(image,0,120,this);
    private void resizeGUI()
    // set window size
    if (screenWidth >= 1280)
    setSize(1024, 768);
    else if (screenWidth >= 1024)
    setSize(800, 600);
    else if (screenWidth >= 800)
    setSize(640, 480);
    // maximize window
    setExtendedState(this.getExtendedState() | this.MAXIMIZED_BOTH);
    public void update(Graphics g) {
    paint(g);
    }

    1) Use the [url http://forum.java.sun.com/help.jspa?sec=formatting]Code Formatting Tags when posting code, so the code is readable. There is also a "Preview" button as well you should be using.
    2) There is no need to override paint() or update() in a Swing application. Thats old code for AWT.
    I am looking for a way to display an image in a jframe. I want to avoid
    wrapping it into a container..such as a JPanel, JLabel..ect.Well thats the way its done in Swing. Read the Swing tutorial on [url http://java.sun.com/docs/books/tutorial/uiswing/14painting/concepts.html]Custom Painting for more information on how painting is done in Swing and you will understand why.
    There actually is a solution in the forum somewhere that allows you to specify a Border, where the Border is actually a image that get painted in the background. Don't remember the posting though. Search the forum using "background image" and you might find it.

  • Problem while encoding JPEG image from JFrame paintComponent in a servlet

    Hello!
    I m developing webapplication in which I made one servlet that calls JFrame developed by me, and then encoding into JPEG image to send response on client browser. I m working on NetBeans 5.5 and the same code runs well. But my hosting server is Linux and I m getting the following error:
    java.awt.HeadlessException:
    No X11 DISPLAY variable was set, but this program performed an operation which requires it.
         java.awt.GraphicsEnvironment.checkHeadless(GraphicsEnvironment.java:159)
         java.awt.Window.<init>(Window.java:406)
         java.awt.Frame.<init>(Frame.java:402)
         java.awt.Frame.<init>(Frame.java:367)
         javax.swing.JFrame.<init>(JFrame.java:163)
         pinkConfigBeans.pinkInfo.pinkModel.pinkChartsLib.PinkChartFrame.<init>(PinkChartFrame.java:36)
         pinkConfigBeans.pinkController.showLastDayRevenueChart.processRequest(showLastDayRevenueChart.java:77)
         pinkConfigBeans.pinkController.showLastDayRevenueChart.doGet(showLastDayRevenueChart.java:107)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
    note The full stack trace of the root cause is available in the Apache Tomcat/5.5.25 logs.
    I m building the application in NetBeans and when runs then it runs well, even while browsing from LAN. But when I place the web folder creted under buil directory of NetBeans in the Tomcat on Linux, then it gives above error.
    Under given is the servlet code raising exception
    response.setContentType("image/jpeg"); // Assign correct content-type
    ServletOutputStream out = response.getOutputStream();
    /* TODO GUI output on JFrame */
    PinkChartFrame pinkChartFrame;
    pinkChartFrame = new PinkChartFrame(ssnGUIAttrInfo.getXjFrame(), ssnGUIAttrInfo.getYjFrame(), headingText, xCordText, yCordText, totalRevenueDataList);
    pinkChartFrame.setTitle("[::]AMS MIS[::] Monthly Revenue Chart");
    pinkChartFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    //pinkChartFrame.setVisible(true);
    //pinkChartFrame.plotDataGUI();
    int width = 760;
    int height = 460;
    try {
    BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
    Graphics2D g2 = image.createGraphics();
    pinkChartFrame.pinkChartJPanel.paintComponent(g2);
    JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
    encoder.encode(image);
    } catch (ImageFormatException ex) {
    ex.printStackTrace();
    response.sendRedirect("index.jsp");
    } catch (IOException ex) {
    ex.printStackTrace();
    response.sendRedirect("index.jsp");
    out.flush();
    Do resolve anybody!
    Edited by: pinkVag on Oct 15, 2007 10:19 PM

    >
    I m developing webapplication in which I made one servlet that calls JFrame developed by me, and then encoding into JPEG image to send response on client browser. I m working on NetBeans 5.5 and the same code runs well. But my hosting server is Linux and I m getting the following error:
    java.awt.HeadlessException: >That makes sense. It is saying that you cannot open a JFrame in an environment (the server) that does not support GUIs!
    To make this so it will work on the server, it will need to be recoded so that it uses the command line only - no GUI.
    What is it exactly that PinkChartFrame is generated an image of? What does it do? (OK probably 'generate a chart') But what APIs does it use (JFreeChart or such)?

  • How to add an image to JFrame....

    Hello evryone,
    Here i'm posting my code..and in this i would like to add a .jpg file as background..I hav tried for imageicon and Bufferdimage...
    Help me out...
    import java.awt.event.*;
    import java.awt.*;
    import java.applet.*;
    import javax.swing.*;
    import java.lang.*;
    import java.awt.image.*;
    import java.awt.Container.*;
    import java.io.FileInputStream.*;
    import java.io.*;
    import javax.imageio.*;
    public class Kbc extends JFrame implements ActionListener
    Container c;
    JButton b1,b2,b3;
    JLabel l;
    public Kbc()
    c = getContentPane() ;
    c.setLayout(null) ;
    l=new JLabel("--:WeLcoMe :--");
    Font f = new Font("Dialog", Font.PLAIN, 24);
    l.setFont(f);
    l.setBounds(300,30,1100,20);
    c.add(l);
    b1=new JButton("START");
    b1.setFont(f);
    b1.setPreferredSize( new Dimension(200,100) ) ;
    b1.setSize( b1.getPreferredSize() ) ;
    b1.setLocation(350,100) ;
    b1.addActionListener(this) ;
    c.add(b1) ;
    b2=new JButton("QUIT");
    b2.setFont(f);
    b2.setPreferredSize( new Dimension(200,100) ) ;
    b2.setSize( b2.getPreferredSize() ) ;
    b2.setLocation(350,210) ;
    b2.addActionListener(this) ;
    c.add(b2) ;
    b3=new JButton("HELP");
    b3.setFont(f);
    b3.setPreferredSize( new Dimension(200,100) ) ;
    b3.setSize( b3.getPreferredSize() ) ;
    b3.setLocation(350,320) ;
    b3.addActionListener(this) ;
    c.add(b3) ;
    setSize(1100,700);
    setVisible(true);
    public void actionPerformed(ActionEvent e)
    if(e.getSource()==b1)
    new Start1();
    this.hide();
    else
    if(e.getSource()==b2)
    System.exit(0);
    if(e.getSource()==b3)
    JOptionPane.showMessageDialog(c,"RuLes"");
    public static void main(String args[])
    Kbc k=new Kbc();
    /*<applet code="Kbc" height=500 width=900>
    </applet>*/
    {code}{code}

    Hi,
    extends JFrame is application.
    If applet extends JApplet.
    Here is an example of the application.
    Please run this way java Kbc test.jpg
    test.jpg is the background image. Please change file name.
    public class Kbc extends JPanel implements ActionListener {
    private JButton b1, b2 , b3 ;
    private JLabel l ;
    static private String filename ;
    private Image image ;
    private JLayeredPane layeredPane ;
    public Kbc() {
         layeredPane = new JLayeredPane() ;
         layeredPane.setPreferredSize( new Dimension(1100,700) ) ;
    l=new JLabel(":Wellcome :");
    Font f = new Font("Dialog", Font.PLAIN, 24);
    l.setFont(f);
    l.setBounds(300,30,1100,20);
    layeredPane.add(l, new Integer( 3 ) );
    b1=new JButton("START");
    b1.setFont(f);
    b1.setPreferredSize( new Dimension(200,100) ) ;
    b1.setSize( b1.getPreferredSize() ) ;
    b1.setLocation(350,100) ;
    b1.addActionListener(this) ;
    layeredPane.add(b1,new Integer( 1 ) ) ;
    b2=new JButton("QUIT");
    b2.setFont(f);
    b2.setPreferredSize( new Dimension(200,100) ) ;
    b2.setSize( b2.getPreferredSize() ) ;
    b2.setLocation(350,210) ;
    b2.addActionListener(this) ;
    layeredPane.add(b2, new Integer( 2 ) ) ;
    b3=new JButton("HELP");
    b3.setFont(f);
    b3.setPreferredSize( new Dimension(200,100) ) ;
    b3.setSize( b3.getPreferredSize() ) ;
    b3.setLocation(350,320) ;
    b3.addActionListener(this) ;
    layeredPane.add(b3, new Integer( 5 )) ;
    add( layeredPane);
    public void paintComponent (Graphics g) {
              super.paintComponent(g);
    try {
    File f = new File(filename);
    BufferedImage image = ImageIO.read(f);
    g.drawImage(image, 0, 0, this);
    } catch (Exception ex) {
    ex.printStackTrace();
    public void actionPerformed(ActionEvent e) {
    if (e.getSource()==b1)
    // new Start1();
    this.setVisible(false) ;
    else if (e.getSource()==b2) {
    System.exit(0);
    } else if (e.getSource()==b3) {
    JOptionPane.showMessageDialog(this,"RuLes");
    public static void main(String args[]) {
    filename = args[0] ;
    SwingUtilities.invokeLater(new Runnable() {
    public void run() {
    createAndShowGUI();
    private static void createAndShowGUI() {
    System.out.println("Created GUI on EDT? "+
    SwingUtilities.isEventDispatchThread());
         Kbc k=new Kbc();
    JFrame frame = new JFrame("Kbc");
         frame.add(k);
    frame.pack();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setPreferredSize(new Dimension(1100, 700 ) );
    frame.setVisible(true);
    }

  • 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

  • Resizing image in JFrame

    Im trying to get the following code to resize the image that is drawn in TrackPanel, im added a resize listener but am not sure how to get the image to resize when the frame is resized.
    import javax.swing.*;
    import java.awt.*;
    import java.awt.Dimension;
    import java.awt.event.*;
    import java.net.URL;
    public class MyFrame {
         public static void main(String[] args)
              Frame frame = new Frame();
    class Frame extends JFrame {
         private Image track;
         public Frame() {
              Class cl = this.getClass();
              Toolkit T = this.getToolkit();
    track = T.getImage("C:\\track6.gif");
              MediaTracker mediaTracker = new MediaTracker(this);
    mediaTracker.addImage(track, 1);
    try {
    mediaTracker.waitForID(1);
    catch (InterruptedException ie) {
    System.err.println(ie);
              addComponentListener(new ComponentAdapter() {
    public void componentResized(ComponentEvent evt) {
    int width = getWidth();
              int height = getHeight();
              TrackPanel track1 = new TrackPanel(track);
              getContentPane().add(track1, null);
              pack();
              setVisible(true);
    class TrackPanel extends JPanel {
         private Image track;
         private int imageWidth;
         private int imageHeight;
         public TrackPanel(Image tr)
              track = tr;
              setPreferredSize(new Dimension(800, 500));
         public void paintComponent(Graphics g)
              g.drawImage(track,0,0, 800,500,this);
    }

    import javax.swing.*;
    import java.awt.*;
    import java.awt.Dimension;
    import java.awt.event.*;
    import java.net.URL;
    public class MyFrame {
         public static void main(String[] args)
              Frame frame = new Frame();
    class Frame extends JFrame {
         private Image track;
         public Frame() {
              Class cl = this.getClass();
              Toolkit T = this.getToolkit();
            track = T.getImage("C:\\track6.gif");
              MediaTracker mediaTracker = new MediaTracker(this);
            mediaTracker.addImage(track, 1);
            try {
                mediaTracker.waitForID(1);
            catch (InterruptedException ie) {
                System.err.println(ie);
              addComponentListener(new ComponentAdapter() {
                public void componentResized(ComponentEvent evt) {
                    int width = getWidth();
                      int height = getHeight();
              TrackPanel track1 = new TrackPanel(track);
              getContentPane().add(track1, null);
              pack();
              setVisible(true);
    class TrackPanel extends JPanel {
         private Image track;
         private int imageWidth;
         private int imageHeight;
         public TrackPanel(Image tr)
              track = tr;
              setPreferredSize(new Dimension(800, 500));
         public void paintComponent(Graphics g)
              g.drawImage(track,0,0, 800,500,this);
    }Sorry this should do it !!!

Maybe you are looking for

  • Data Type NUMC from R3 to BW

    Hi Expertts, The datatype NUMC holding a value 00000 in R3 becomes SPACE or NULL by the time it reaches to PSA.  Is there a way to prevent this from happening.  I want the value intact when and the same when it reaches the PSA up to the cube. Thanks

  • Separate Queries, Separate Group By's w/ Wizard

    I used the wizard to create a report w/ two queries. Using the wizard, I set the first query to designate a specific field as a group field. When I added the second query via the wizard, the step to set a field as a group field was skipped over. I ne

  • Using AUTHID = CURRENT_USER and Apex

    I'm new to Apex and am just assessing if we can make use of it, mainly for reporting functionality in our existing web based application. We have a schema that holds all of our procedures, packages, functions etc and they all have AUTHID = CURRENT_US

  • Need documentation on IXOS Archive Administration n configuration with SAP

    Could someone send me some step by step documentation on IXOS Archive Administration and configuration with SAP. Would be really appreciative cause i need to start this work immediately in my company.

  • Dynamic naming of Vectors

    Hi, I need to be able to create vectors dynamically, for example vectorName1, vectorName2 and so on. I've managed to do this with JButtons using setName(). Is there a similar way to set the name of vectors using a string? Thanx