Adding Image to JPanel?

Hi all,
I am new to Swing..
How to add the "Image" to JPanel.
if anyone knows please help me..
Thanks

Here's a long reply involving several classes, some obtained directly from Sun for reuse. These allow you to fill an image in a panel as the background to your frame. You can add components on top of this background image. If this isn't what you wanted, excuse my misunderstanding:
First, you need a panel for your frame:
<code>
public class FramePanel extends JPanel
* Initialized by the (first call to the) constructor. This
* Fill is used to paint the entire panel.
private static TiledFill tiledFill = null;
/*Constructors */
public FramePanel()
super();
setOpaque(true);
* Create a TiledFill object to draw the
* background from preferences properties file
public void getBackgroundImage()
setForeground(Color.BLACK);
setBackground(Color.WHITE);
if (tiledFill == null)
try
FileImageInputStream file = new FileImageInputStream(*your image's file location*);
BufferedImage image = ImageIO.read(file);
ImageFill fill = new ImageFill(image);
tiledFill = new TiledFill(fill, image.getWidth(), image.getHeight());
catch (IOException e)
e.printStackTrace();
JOptionPane pane = new JOptionPane("Could not retrieve image in FramePanel");
pane.setVisible(true);
* Paint the area within <code>g.getClipBounds()</code>
* making sure that the new tiles are aligned with a tileWidth
* by tileHeight grid whose origin is at 0,0.
public void paintComponent(Graphics g)
super.paintComponent(g);
getBackgroundImage();
/* To ensure that the tiles we paint are aligned with
* a tileWidth X tileHeight grid whose origin is 0,0 we
* enlarge the clipBounds rectangle so that its origin
* is aligned with the origin of a tile and its size
* is a multiple of the tile size.
Rectangle clip = g.getClipBounds();
int tw = tiledFill.getTileWidth();
int th = tiledFill.getTileHeight();
int x = (clip.x / tw) * tw;
int y = (clip.y / th) * th;
int w = (((clip.x + clip.width + tw - 1) / tw) * tw) - x;
int h = (((clip.y + clip.height + th - 1) / th) * th) - y;
Graphics gFill = g.create();
tiledFill.paintFill(this, gFill, new Rectangle(x, y, w, h));
gFill.dispose();
</code>
Now you need the fill and tiled fill classes size the image.
<code>
import java.awt.*;
public class Fill
public void paintFill(Component c, Graphics g, Rectangle r)
g.setColor(c.getBackground());
g.fillRect(r.x, r.y, r.width, r.height);
public void paintFill(Container c, Graphics g)
Insets insets = c.getInsets();
int x = insets.left;
int y = insets.top;
int w = c.getWidth() - (insets.left + insets.right);
int h = c.getHeight() - (insets.top + insets.bottom);
paintFill(c, g, new Rectangle(x, y, w, h));
public void paintFill(Component c, Graphics g, int x, int y, int w, int h)
paintFill(c, g, new Rectangle(x, y, w, h));
</code>
<code>
import java.awt.*;
import java.awt.image.*;
* Displays a single <code>BufferedImage</code>, scaled to fit the
* <code>paintFill</code> rectangle.
* <pre>
* BufferedImage image = ImageIO.read(new File("background.jpg"));
* final ImageFill imageFill = new ImageFill(image);
* JPanel p = new JPanel() {
* public c void paintComponent(Graphics g) {
*     imageFill.paintFill(this, g);
* </pre>
* Note that animated gifs aren't supported as there's no image observer.
public class ImageFill extends Fill
private final static int IMAGE_CACHE_SIZE = 8;
private BufferedImage image;
private BufferedImage[] imageCache = new BufferedImage[IMAGE_CACHE_SIZE];
private int imageCacheIndex = 0;
* Creates an <code>ImageFill</code> that draws <i>image</i>
* scaled to fit the <code>paintFill</code> rectangle
* parameters.
* @see #getImage
* @see #paintFill
public ImageFill(BufferedImage image)
this.image = image;
* Creates an "empty" ImageFill. Before the ImageFill can be
* drawn with the <code>paintFill</code> method, the
* <code>image</code> property must be set.
* @see #setImage
* @see #paintFill
public ImageFill()
this.image = null;
* Returns the image that the <code>paintFill</code> method draws.
* @return the value of the <code>image</code> property
* @see #setImage
* @see #paintFill
public BufferedImage getImage()
return image;
* Set the image that the <code>paintFill</code> method draws.
* @param image the new value of the <code>image</code> property
* @see #getImage
* @see #paintFill
public void setImage(BufferedImage image)
this.image = image;
for (int i = 0; i < imageCache.length; i++)
imageCache[i] = null;
* Returns the actual width of the <code>BufferedImage</code>
* rendered by the <code>paintFill</code> method. If the image
* property hasn't been set, -1 is returned.
* @return the value of <code>getImage().getWidth()</code> or -1 if
* getImage() returns null
* @see #getHeight
* @see #setImage
public int getWidth()
BufferedImage image = getImage();
return (image == null) ? -1 : image.getWidth();
* Returns the actual height of the <code>BufferedImage</code>
* rendered by the <code>paintFill</code> method. If the image
* property hasn't been set, -1 is returned.
* @return the value of <code>getImage().getHeight()</code> or -1 if
* getImage() returns null
* @see #getWidth
* @see #setImage
public int getHeight()
BufferedImage image = getImage();
return (image == null) ? -1 : image.getHeight();
* Create a copy of image scaled to width,height w,h and
* add it to the null element of the imageCache array. If
* the imageCache array is full, then we replace the "least
* recently used element", at imageCacheIndex.
private BufferedImage createScaledImage(Component c, int w, int h)
GraphicsConfiguration gc = c.getGraphicsConfiguration();
BufferedImage newImage = gc.createCompatibleImage(w, h, Transparency.TRANSLUCENT);
boolean cacheOverflow = true;
for (int i = 0; i < imageCache.length; i++)
Image image = imageCache;
if (image == null)
imageCache[i] = newImage;
cacheOverflow = false;
break;
if (cacheOverflow)
imageCache[imageCacheIndex] = newImage;
imageCacheIndex = (imageCacheIndex + 1) % imageCache.length;
Graphics g = newImage.getGraphics();
int width = image.getWidth();
int height = image.getHeight();
g.drawImage(image, 0, 0, w, h, 0, 0, width, height, null);
g.dispose();
return newImage;
* Returns either the image itself or a cached scaled copy.
private BufferedImage getFillImage(Component c, int w, int h)
if ((w == getWidth()) && (h == getHeight()))
return image;
for (int i = 0; i < imageCache.length; i++)
BufferedImage cimage = imageCache[i];
if (cimage == null)
break;
if ((cimage.getWidth(c) == w) && (cimage.getHeight(c) == h))
return cimage;
return createScaledImage(c, w, h);
* Draw the image at <i>r.x,r.y</i>, scaled to <i>r.width</i>
* and <i>r.height</i>.
public void paintFill(Component c, Graphics g, Rectangle r)
if ((r.width > 0) && (r.height > 0))
BufferedImage fillImage = getFillImage(c, r.width, r.height);
g.drawImage(fillImage, r.x, r.y, c);
</code>
Now it's just a simple matter of creating a frame and making the frame panel the frame's content pane:
<code>
import java.awt.BorderLayout;
import java.awt.HeadlessException;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.UIManager;
public class ImageFrame extends JFrame
private FramePanel framePanel;
//start of constructors
public ImageFrame() throws HeadlessException
super();
init();
public ImageFrame(String title) throws HeadlessException
super(title);
init();
// end of constructors
void init()
try
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
catch (Exception e)
System.out.println ("Unknown Look and Feel");
     framePanel = new FramePanel();
     this.getContentPane().add(framePanel, BorderLayout.CENTER);
     this.setContentPane(framePanel);
     ((JPanel)this.getContentPane()).setOpaque(false);
</code>

Similar Messages

  • Adding iamge to JPanel but it is not display in it's original size.

    hi,
    I am trying to add Image to JPanel successfully, but it' s visible in panel as a small icon rather then it's original size.
    First i creating a panel class and after that adding this panel to JFrame. I am using BufferedImage. I have tried it all the way but it's not working.Anybody have any idea about the problem.
    Thanks

    rule #1 when you have problem with code: post the code! How do you expect people to help you if you give them nothing but the plea for help?
    rule #2: use the code tags (when you paste your code, select it and press the code button) to format it so it is easy to read.

  • Error while adding Image: ORA-00001: unique constraint

    Dear all,
    I have an error while adding images to MDM I can´t explain. I want to add 7231 images. About 6983 run fine. The rest throws this error.
    Error: Service 'SRM_MDM_CATALOG', Schema 'SRMMDMCATALOG2_m000', ERROR CODE=1 ||| ORA-00001: unique constraint (SRMMDMCATALOG2_M000.IDATA_6_DATAID) violated
    Last CMD: INSERT INTO A2i_Data_6 (PermanentId, DataId, DataGroupId, Description_L3, CodeName, Name_L3) VALUES (:1, :2, :3, :4, :5, :6)
    Name=PermanentId; Type=9; Value=1641157; ArraySize=0; NullInd=0;
    Name=DataId; Type=5; Value=426458; ArraySize=0; NullInd=0;
    Name=DataGroupId; Type=4; Value=9; ArraySize=0; NullInd=0;
    Name=Description_L3; Type=2; Value=; ArraySize=0; NullInd=0;
    Name=CodeName; Type=2; Value=207603_Img8078_gif; ArraySize=0; NullInd=0;
    Name=Name_L3; Type=2; Value=207603_Img8078.gif; ArraySize=0; NullInd=0;
    Error: Service 'SRM_MDM_CATALOG', Schema 'SRMMDMCATALOG2_m000', ERROR CODE=1 ||| ORA-00001: unique constraint (SRMMDMCATALOG2_M000.IDATA_6_DATAID) violated
    Last CMD: INSERT INTO A2i_Data_6 (PermanentId, DataId, DataGroupId, Description_L3, CodeName, Name_L3) VALUES (:1, :2, :3, :4, :5, :6)
    Name=PermanentId; Type=9; Value=1641157; ArraySize=0; NullInd=0;
    Name=DataId; Type=5; Value=426458; ArraySize=0; NullInd=0;
    Name=DataGroupId; Type=4; Value=9; ArraySize=0; NullInd=0;
    Name=Description_L3; Type=2; Value=; ArraySize=0; NullInd=0;
    Name=CodeName; Type=2; Value=207603_Img8085_gif; ArraySize=0; NullInd=0;
    Name=Name_L3; Type=2; Value=207603_Img8085.gif; ArraySize=0; NullInd=0;
    I checked all data. There is no such dataset in the database. Can anybody give me a hint how to avoid this error.
    One thing I wonder: The PermanentId is allways the same but I can´t do anything here.
    BR
    Roman
    Edited by: Roman Becker on Jan 13, 2009 12:59 AM

    Hi Ritam,
    For such issues, can you please create a new thread or directly email the author rather than dragging back up a very old thread, it is unlikely that the resolution would be the same as the database/application/etc releases would most probably be very different.
    For now I will close this thread as unanswered.
    SAP SRM Moderators.

  • Apple have a big flaw adding images to Apple TV coding error.

    Hi all, it seems Apple have a big flaw in there new version of itunes 8.2.0.23.
    So heres the problem if you have a Apple Tv system. Adding images is great however the softwares flaw is when you have a lot of images. i have over 3000, and tick boxes apear half way in the list, for know reason.
    i have add a link to show you guys and girls a screen shot...
    can anyone from apple sort this out?
    it really bugging me. as it happens of vista, xp, windows 7, and osx.
    Cheers
    Adam
    null

    apple don't monitor the forums for bug reports... this is a user-to-user support forum.
    you should report it via the official method - http://www.apple.com/feedback/appletv.html

  • Adding Images to the List component

    Adding Images to the List component while using the FLV
    PLayback
    All, ( i can send you my source files if it would help)
    I'm using the FLV Playback component and loading videos into
    it from an external xml file. I also have a list component tied to
    the FLV playback that when you click on one of the elements in the
    list, it plays that movie.
    QUESTION:
    My question is how do I add an image to the list component?
    Below is the xml file and the actionscript. I've added the image
    attribute to the XML file as img="time_square.jpg" and added the
    element of the array when calling/creating the list. Did I do this
    right?
    Any direction would be very much appreciated.

    Adding Images to the List component while using the FLV
    PLayback
    All, ( i can send you my source files if it would help)
    I'm using the FLV Playback component and loading videos into
    it from an external xml file. I also have a list component tied to
    the FLV playback that when you click on one of the elements in the
    list, it plays that movie.
    QUESTION:
    My question is how do I add an image to the list component?
    Below is the xml file and the actionscript. I've added the image
    attribute to the XML file as img="time_square.jpg" and added the
    element of the array when calling/creating the list. Did I do this
    right?
    Any direction would be very much appreciated.

  • Background image  for JPanel using UI Properties

    Is there any way to add background image for JPanel using UI Properties,
    code is
    if (property.equals("img")) {
    System.out.println("call image file in css"+comp);
    //set the background color for Jpanel
    comp.setBackground(Color.decode("#db7093"));
    here the comp is JPanel and we are setting the background color,
    Is there any way to put the Background image for the JPanel ????

    KrishnaveniB wrote:
    Is there any way to put the Background image for the JPanel ????Override the paintComponent(...) method of JPanel.
    e.g.
    import javax.swing.*;
    import java.awt.*;
    import java.io.*;
    import javax.imageio.ImageIO;
    public class ImagePanel {
        public void createAndShowUI() {
            try {
                JFrame frame = new JFrame("Background Image Demo");
                final Image image = ImageIO.read(new File("/home/oje/Desktop/icons/yannix.gif"));
                JPanel panel = new JPanel() {
                    protected void paintComponent(Graphics g) {
                        g.drawImage(image, 0, 0, null);
                frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                frame.setSize(new Dimension(400, 400));
                frame.setContentPane(panel);
                frame.setLocationRelativeTo(null);
                frame.setVisible(true);
            } catch (IOException ex) {
                ex.printStackTrace();
        public static void main(String[] args) {
            SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    new ImagePanel().createAndShowUI();
    }

  • Displyaing image in JPanel

    I am using below code to display image in jpanel.
    It is not displaying image. Please help me.
    import java.util.Vector;
    import javax.swing.*;
    import javax.swing.border.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.awt.Toolkit;
    import java.awt.Image;
    public class project extends JPanel {
         public void init()
              JFrame mFrame = new JFrame("Documentum Login");
              mFrame.setSize(350,200);
    //mFrame.setResizable(false);
    Dimension dim = getToolkit().getScreenSize();
    mFrame.setLocation((dim.width/2) - (mFrame.getWidth()/2),(dim.height/2) - (mFrame.getHeight()/2));
              //JPanel hpan = new JPanel();
    //hpan.setLayout(new BoxLayout(hpan,BoxLayout.Y_AXIS));
    //hpan.setBorder(new TitledBorder (new LineBorder (Color.blue, 1)));
              //Image img = Toolkit.getDefaultToolkit().getImage("D:/Temp/test.jpg");
              ImageIcon icon = new ImageIcon("D:\\Temp\\test.jpg");
              JLabel imageLabel = new JLabel(icon);
              JScrollPane scrollPane = new JScrollPane (JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
              scrollPane.getViewport().add(imageLabel);
              JPanel panel = new JPanel();
              panel.setLayout(new BorderLayout());
              panel.add(scrollPane,BorderLayout.CENTER);
              mFrame.getContentPane().add(panel);
    mFrame.addWindowListener(new WindowAdapter(){
    public void windowClosing(WindowEvent e) {System.exit(0); }
    mFrame.setVisible(true);
         public static void main(String args[])
              project pr = new project();
              pr.init();          
    }

    Don't add() to a JViewport, setView() instead.

  • Adding images and buttons without a frame appearing

    I would like to add images to some of my pages without having them appear in a frame. I would like to place some transparent gifs on the page to use as buttons for hyperlinks. I would also like to have some photos (with transparent backgrounds that appear on the page and are not surrounded by a picture frame. Any Suggestions

    iWeb seems to default to stroking newly-added images and shapes. Pages (iWeb's close relation) includes a way to change the default appearance, but I can't find anything similar in iWeb. You can, of course, remove the stroke using the Graphic Inspector (just set Stroke to None). Transparency in gifs and photo images is supported. Just drag into iWeb or use Insert > Choose... Again, remove the stroke if this appears.

  • Display a transparent image in JPanel

    i just start using Java Graphics Programming fews month ago. there's some problem i facing recently. i doing a simple gif file viewer. first i get the file using the Toolkit and put it in a Image object and use the Gif Decoder to decoded each frame of the Gif File to BufferedImage object and display each of the frame in a JPanel inside a JFrame.My porblem is :-
    How to display a transparent image in JPanel? my image source in BufferedImage and how to i know the image is transparent or not?

    I simply use ImageIcon object to display the image (*.gif,*.jpg)
    JLabel l=new JLabel(new ImageIcon("file path"));
    add the label to a panel or frame or dialog
    this object no need to use the ImageBuffered Object
    It can display any animate gif whether the background is transparent or not.

  • Background layer seizes added images.

    I am trying to create a photo collage by scratch (not using "Collage"). First I create a new blank page for the background and save it. It is shown as "locked" with a padlock. Then I open an image file (.jpg) to add to the background layer, and I get a message that I need to unlock the background layer so I click to unlock it. However the added image locks onto the background layer and doesn't make a new layer. If I open another image file it locks on top of the others.

    The Layers panel only shows the layer(s) belonging to the currently active file. You need to arrange your image windows so that you can see your composite image as well as the source. With the source image active the Layers panel will show the source - click and drag that layer to the composite.
    So in the following, the violet image is the active image and I drag its layer to the white image I've created for my collage. In the composite image with the new layer selected I can position it where I want. Select each of the other images in turn and do the same. Refer to my previous note, you can also do this with Copy & Paste.
    When finished, your composite image and its Layers panel will look like this:
    Cheers,
    Neale
    Insanity is hereditary, you get it from your children
    If this post or another user's post resolves the original issue, please mark the posts as correct and/or helpful accordingly. This helps other users with similar trouble get answers to their questions quicker. Thanks.

  • Having trouble displaying image in JPanel

    I want to display an image in jpanel making it to scale to the size of the panel.
    And later i should be able to draw on that image , i am really new to all this , but i have to finish it soon.
    This is the code i am compiling and getting error
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class LocaterClient extends JFrame
         JPanel panel;
         public LocaterClient()
              super("LocaterClient");
              panel = new JPanel();
              panel.setSize(374,378);
              panel.setOpaque(false);
              panel.setVisible(true);
         getContentPane().add(panel);
         /*JFrame f = new JFrame();
         f.setSize(374,378);
         f.getContentPane().add(panel);*/
         public void paintComponent(Graphics g)
              super.paintComponent(g);
              ImageIcon img = new ImageIcon("World_MER.jpg");
              ImageIcon fillImage = new ImageIcon(img.getImage().getScaledInstance
    (getWidth(), getHeight(),Image.SCALE_REPLICATE));
              g.drawImage(fillImage.getImage(), 0,0, this);
         public static void main(String args[])
              LocaterClient lc = new LocaterClient();
              lc.setDefaultCloseOperation( EXIT_ON_CLOSE );
              lc.pack();
              lc.setVisible(true);
    This is the error i am getting
    LocaterClient.java:24: cannot resolve symbol
    symbol : method paintComponent (java.awt.Graphics)
    location: class javax.swing.JFrame
    super.paintComponent(g);
    ^
    1 error
    If i remove super.paintComponent(g); line it compiles and runs but i get a tiny panel without the image.
    PLease help me , i am not evn sure is this is the procedure should i follow , because i should be able to draw on that image later on .
    Please provide me with some sample code.

    import javax.swing.*;
    import java.awt.*;
    public class ImagePainter extends JPanel{
      private Image img;
      public ImagePainter(){
        img = Toolkit.getDefaultToolkit().getImage("MyImage.gif");
      public void paintComponent(Graphics g){
        g.drawImage(img,0,0,getSize().width,getSize().height);
      public static void main(String[]args){
        JFrame frame = new JFrame();
        frame.getContentPane.add(new ImagePainter());
        frame.setSize(500,500);
        frame.show();

  • Adding Image to Search Results

    Hi
    I am dire need of adding images to search results, particularly the thumb of the resulting product(s). The tags TAG_NAME and TAG_DESCRIPTION work, but TAG_SMALLIMAGE doesn't. Any help would be much appreciated.
    Thanks, Teejay

    The CSS in http://dandeliongiftshop.businesscatalyst.com/StyleSheets/ModuleStyleSheets.css is causing that overlap.
    Search for the below style rule in the above CSS file and make suggested modifications:
    .cataloguetitle {
        color: #732772;    font-family: Arial,Helvetica,sans-serif;
        font-size: 14px;
        font-style: normal;
        font-weight: normal;
        position: fixed;          --remove this
        display: block;          --add this
        text-align: center;     --remove this
        text-align: left;          --add this
    Should look better.

  • Displaying DICOM images in JPanel

    Can anyone please tell me how to display DICOM images using JPanel? I can use JPanel to display ordinary images but it does not seem to work using DICOM images. Can anyone please help me out? I've spent hours and hours trying to solve this problem. Thank you in advance.

    Can anyone please tell me how to display DICOM images
    using JPanel? I can use JPanel to display ordinary
    images but it does not seem to work using DICOM
    images. Can anyone please help me out? I've spent
    hours and hours trying to solve this problem. Thank
    you in advance.The JPanel is only able to display JPEG and GIF images, you will need to decode the DICOM image first and convert to JPEG or GIF format, there are some source codes available on the net. Also check this link out
    http://www.dclunie.com/medical-image-faq/html/part8.html

  • Adding Image problems

    Having some problems adding images.
    I was able to add the Ubuntu server image mentioned in the install guide and it is working 
    It appears on the nodes palette and I can create a topology with it and boot it.
    I was also able to add CSR image csr1000v-universalk9.03.13.00a.S.154-3.S0a-ext.qcow2 to the server.  
    However the CSR icon isn't available on the node palette.  How do I fix this?
    How to add other vmdk or ovf style images?  
    I have a network emulator that runs as a VM and comes as a vmdk.   I tried installing it and I get the following message ...  -Cannot create image "server-DummyCloud": Failed to convert image to QCOW2: Command '['qemu-img', 'convert', '-O', 'qcow2', '/tmp/tmpnfp_m_', '/tmp/tmpWk3al7']' returned non-zero exit status 1
    Where can I find compatible NXos images?  

    No change.
    Still get the message ..
    Cannot create image "server-DummyCloud": Failed to convert image to QCOW2: Command '['qemu-img', 'convert', '-O', 'qcow2', '/home/virl/dc.vmdk', '/tmp/tmpmgCkzK']' returned non-zero exit status 1
    I"ll open a tac case.

  • Putting an Image in JPanel

    I am trying to put an image in JPanel. Using something other than ImageIcon. When I run the program only a white screen appears.
    package game;
    import gui.FullScreenDisplay;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.lang.Runnable;
    import java.lang.Thread;
    public class Runner implements Runnable
         private static final long serialVersionUID = 1L;
         private FullScreenDisplay display;
         public static void main(String args[])
              Thread t = new Thread(new Runner());
              t.start();
         public Runner()
              makeGui();
         private void makeGui()
              display = new FullScreenDisplay(this);
         public void run()
              try {
                   Thread.sleep(1000);
              } catch (InterruptedException e) {/*Nothing to do*/}
              run();
         public void quit()
              System.exit(0);
    package gui;
    import game.Runner;
    import java.awt.GraphicsEnvironment;
    import java.awt.event.KeyEvent;
    import javax.swing.KeyStroke;
    import javax.swing.AbstractAction;
    import java.awt.event.ActionEvent;
    import javax.swing.JComponent;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import java.awt.Graphics;
    import java.awt.Image;
    import javax.imageio.ImageIO;
    import java.io.File;
    import java.io.IOException;
    public class FullScreenDisplay extends JFrame {
         private static final long serialVersionUID = 1L;
         private Runner master;
         private JPanel mainPanel;
         private Image tempImage;
         public FullScreenDisplay(Runner master)
              super();
              //Remove this eventually.
              try {
                   tempImage = ImageIO.read(new File("test_image.jpg"));
              } catch (IOException e) {
                   System.out.println("image get error");
                   e.printStackTrace();
              this.master = master;
              makeFrame();
              makePanel();
              makeKeyBindings();
              //setFullScreen(chooseBufferStrategy());
              setFullScreen();
              requestFocus();
              setVisible(true);
              //Remove this eventually.
              Graphics g = tempImage.getGraphics();
              mainPanel.paint(g);
              this.update(g);
         private void makeFrame()
              setUndecorated(true);
              setResizable(false);
              setFocusable(true);
         private void makePanel()
              mainPanel = new JPanel(){
                   public void paintComponent(Graphics g) {
                        if(tempImage == null){
                             System.out.println("Balls");
                        g.drawRect(10, 10, 10, 10);
                        g.drawImage(tempImage,0,0,null);
                        super.paintComponent(g);
                        System.out.println("Did it work");
              add(mainPanel);
         private void makeKeyBindings()
              mainPanel.setFocusable(true);
              //Key bindings... don't like using a string to index, find out if there's a better way.
              mainPanel.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), "exit");
              mainPanel.getActionMap().put("exit", new AbstractAction(){
                   public void actionPerformed(ActionEvent e)
                        master.quit();
         /*private void chooseBufferSrategy()
         private void setFullScreen()
              GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().setFullScreenWindow(this);
    }

    super.paintComponent(g);should be the first line in paintComponent()
    also, you don't really need the keyBindings to quit,
    just set the default close to exit and Alt-F4 will close/quit

Maybe you are looking for

  • Creation of PO from Sales Order

    Hi Please let me know if there is any standard oracle functionality by which we can ensure that Purchase Orders does not contain items from sales orders. e.g. if there are multiple sales order then one PO should be generated for each sales order. At

  • If I drag a external drive from devices to favorites, it disappears

    Whenever I plug in an external drive or USB drive it shows up in Devices, as usual. But if I drag it into the Favorites section, it disappears, and there is no way for me to access the files inside. The mac still recognizes the device but it is not a

  • SOAPHeader doesn't correspond to web service executed

    Hi experts, I'm developing a set of services that use the same business service as sender. When testing with SOAPUI and others this situation happens: 1) The first time I execute a web service, for example XPTO1, the execution is successful 2) When,

  • [svn:fx-3.5.0] 12683: integrate:

    Revision: 12683 Revision: 12683 Author:   [email protected] Date:     2009-12-08 18:47:44 -0800 (Tue, 08 Dec 2009) Log Message: integrate: Flash Player 10: 10.0.42.34 Flash Player 9: 9.0.260.0 AIR 1.5.3: 20091120ap checkintests: pass Modified Paths:

  • Data load management and CTS

    hi sdn, can any one explain data load management and CTS regards andrea