Display an image on a JPanel

Hi,
I am confused about all the MediaTracker and BufferedImage class used to display an image file (e.g. GIF or JPG) on a JPanel
Can someone provide the steps and also the code snippet of the JPanel's paint() method?
I want to display an image directly on the JPanel.
Thank you.

"the scrollpane doesn't work" is not very descriptive.
So I can't help you with that problem.
The suggested code given to you may not work in all
situations:
1) super.paintComponent(..) tells the panel to paint
all its children (in case you've added any other
components to the panel).
2) drawImage() tells the panel to draw the image over
top of all the children (which defeats the whole
purpose of doing the super.paintComponent())
The safer order should be:
1) drawImage()
2) setOpaque( false )
3) super.paintComponent().
This approach will then work for adding images to the
background of a textArea, textPane etc.Good point that I did not consider since my JPanel is exclusively used for an image with no components added.
If your image is known not to have an alpha channel, you could setOpaque(false) in the extended JPanel's constructor and avoid recalling for every paint (as I am able to do in my situation). You'll probably want to do this in otherwise:
setOpaque(true);
drawImage(image,x,y,observer);
setOpaque(false);
super.paintComponent(g);
since the next call to paintComponent() will already be setOpaque(false) (unless it is automatically reset, which I haven't seen).
Robert Templeton

Similar Messages

  • How to display tow images in a JPanel

    hello
    I want to display tow images at the same time in a class which extends a JPanel,and the super image is expected to move at will.But the super image is always overlaying the lower one.I have tried to call the setGlassPane() in a JFrame and it works!But how to do in a JPanel?
    Here is my code:
    import java.awt.*;
    import java.awt.geom.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.event.*;
    public class SlideRheostat extends JPanel
    Image imageRheostat,imageSlip;
    Rectangle rec;
    public SlideRheostat()
         imageRheostat=Toolkit.getDefaultToolkit().getImage("imageRheostat.gif");
         imageSlip=Toolkit.getDefaultToolkit().getImage("imageSlip.gif");
    public void paint(Graphics g,Rectangle rec)
         g.drawImage(imageRheostat,0,0,imageRheostat.getWidth(),imageRheostat.getHeight(),this);
         g.drawImage(imageSlip,20,20,imageSlip.getWidth(),imageSlip.getHeight(),this);

    hello
    I want to display tow images at the same time in a class which extends a JPanel,and the super image is expected to move at will.But the super image is always overlaying the lower one.I have tried to call the setGlassPane() in a JFrame and it works!But how to do in a JPanel?
    Here is my code:
    import java.awt.*;
    import java.awt.geom.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.event.*;
    public class SlideRheostat extends JPanel
    Image imageRheostat,imageSlip;
    public SlideRheostat()
    imageRheostat=Toolkit.getDefaultToolkit().getImage("imageRheostat.gif");
    imageSlip=Toolkit.getDefaultToolkit().getImage("imageSlip.gif");
    public void paint(Graphics g)
    g.drawImage(imageRheostat,0,0,imageRheostat.getWidth(),imageRheostat.getHeight(),this);
    g.drawImage(imageSlip,20,20,imageSlip.getWidth(),imageSlip.getHeight(),this);

  • How do I draw an image on a JPanel?

    To be honest I have no idea even where to start. I tried hacking through the tutorials but it just didn't help me (normally they do, I don't what's up).
    Anyway, so what I'm trying to do is build a game. The Graphics2D is great for simple shapes but drawing characters is getting kind of ridiculous (tedious + difficult + looks bad). So, I need to figure out how to display an image on a JPanel.
    To that end I have several questions.
    1 - What image type do I use? Like jpeg, bmp, gif, etc.
    2 - How do I make parts of it transparent?
    3 - How do I make it appear on the screen, given some coordinates on the JPanel?

    To draw an image directly to a JPanel given certain coordinates, you have to create a custom JPanel and override its paintComponent() method. Like this:
    class PaintPanel extends JPanel{
    public void paintComponent(Graphics g){
    super.paintComponent(g);
    //painting code goes here}
    }Java can load in and draw GIF and JPEG images. If you decide to use GIF files, any good image editor like Adobe Photoshop should be able to make them transparent for you before the fact. If you want to set transparency within your java program you will have to create a BufferedImage and make certain colors within it transparent, but I would like to know how to do that as much as you do.

  • Displaying an image in JPanel

    I have have class called TopPanel which extends a JPanel. The Layout is BorderLayout.
    JMenuBar is BorderLayout.NORTH
    JToolBar is BorderLayout.SOUTH
    I have an image which I want to display on the right hand corner of the panel.
    But if do
    add(image,BorderLayout.EAST) , it does not display the image .
    This is the pseudo code
    public class TopPanel extends JPanel{
           public TopPanel() {
                setLayout(new BorderLayout();
                add(menuBar,BorderLayout.NORTH);   //these get added
                add(toolBar,BorderLayout.SOUTH);
                add(image,BorderLayout.EAST);
    thank you.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

    It's just not the image alone, I added a JLabel to test it . Even that doesn't display.

  • 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

  • Displaying the content of one JPanel in an other as a scaled image

    Hi,
    I'd like to display the content of one JPanel scaled in a second JPanel.
    The first JPanel holds a graph that could be edited in this JPanel. But unfortunately the graph is usually to big to have a full overview over the whole graph and is embeded in a JScrollPanel. So the second JPanel should be some kind of an overview window that shows the whole graph scaled to fit to this window and some kind of outline around the current section displayed by the JScrollPanel. How could I do this?
    Many thanks in advance.
    Best,
    Marc.

    Hi,
    I'd like to display the content of one JPanel scaled
    in a second JPanel.
    The first JPanel holds a graph that could be edited
    in this JPanel. But unfortunately the graph is
    usually to big to have a full overview over the whole
    graph and is embeded in a JScrollPanel. So the second
    JPanel should be some kind of an overview window that
    shows the whole graph scaled to fit to this window
    and some kind of outline around the current section
    displayed by the JScrollPanel. How could I do this?
    Many thanks in advance.
    Best,
    Marc.if panel1 is the graph and panel2 is the overview, override the paintComponent method in panel2 with this
    public void paintComponent(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;
    g2.scale(...,...);
    panel1.paint(g2);
    }

  • Animated GIF Image on a JPanel.

    How can I display an animated GIF image on a JPanel? It should animate after displaying.
    Regards

    I think this code should display an animated GIF image on a JPanel.
    -Mani
    import javax.swing.*;
    import java.awt.event.WindowAdapter;
    import java.awt.event.WindowEvent;
    import java.awt.*;
    public class Animation {
    public static void main(String args[]) {
    JLabel imageLabel = new JLabel();
    JLabel headerLabel = new JLabel();
    JFrame frame = new JFrame("JFrame Animation");
    JPanel jPanel = new JPanel();
    //Add a window listner for close button
    frame.addWindowListener(new WindowAdapter() {
    public void windowClosing(WindowEvent e) {
    System.exit(0);
    // add the header label
    headerLabel.setFont(new java.awt.Font("Comic Sans MS", Font.BOLD, 16));
    headerLabel.setText("Animated Image!");
    jPanel.add(headerLabel, java.awt.BorderLayout.NORTH);
    //frame.getContentPane().add(headerLabel, java.awt.BorderLayout.NORTH);
    // add the image label
    ImageIcon ii = new ImageIcon("d:/dog.gif");
    imageLabel.setIcon(ii);
    jPanel.add(imageLabel, BorderLayout.CENTER);
    frame.getContentPane().add(jPanel, java.awt.BorderLayout.CENTER);
    frame.pack();
    frame.setVisible(true);
    }

  • How to use a backgroud image in a JPanel.....

    hi,
    How can I display a background image for a JPanel.....
    I have searched this forum but all solutions I found are where JPanel at the end has to be displayed on a frame in an application...
    I need to use JPanel on Applet.......
    Actually I am switching JPanels on JApplet as screens for a game....
    I need to display background image for one of the JPanel class that has to be called by an Applet class....
    Thanks a lot for any help.

    Thanks a lot for your help.
    How do we specify URL to use an image from net. Is itt like I open an image file on some website & use its address? Kindly add here some website too so that its more clear for me.
    Thanks a lot for any help & all help your provided previously.
    String imageFilePath = "urlOfMyImageFile"; // I am asking about parameter to be used here
    ImageIcon ii = new ImageIcon(imageFilePath);
    Image image = ii.getImage();

  • Need help in displaying an Image in a JLabel

    Hi everyone,
    I am using a JLabel to display images on a particular screen. I am facing some problem while doing so..
    On my screen there are images of some garments. When the users select colors from a particular list, i should color this garment images and load it on the screen again with the colors. I have a floodfill class for filling the colors in the images. The problem I am facing is I am able to color the image properly with my floodfill class but when displaying the image on the same jlabel, the image gets distorted somehow.
    Everytime I color the image, I create an ImageIcon of the image and use the seticon method from the JLabel class. First I set the icon to null and then set it to the imageicon created. here is the code I use.
    If 'image' is the the image i have to load
    ImageIcon imgicon = new ImageIcon(image);
    jlabel.setIcon(null);
    jlabel.setIcon(imgicon);I am setting the icon to null because I have not found any other method to clear the previous image from the jlabel.
    Can anyone who has worked on images before and faced a similar situation help me with this?? Is there some other container I can use besides the JLabel to display the images perhaps?
    Thanks in advance.....
    Bharat

    And the thing is when I first go into that screen with the selected colors it is displaying the images perfectly.
    It is only giving problems when I pick different colors on the screenit really sounds like the problem is in your floodfill class.
    I have no idea what's in floodfill, but if you were e.g. using a JPanel and paintComponent,
    you would need to have as the first line in paintComponent()
    super.paintComponent(..);
    to clear the previous painting.
    if not, you would be just drawing over the top of the previous paintComponent(), and if the calculation of the
    painting area is not 100% exact, you may get the odd pixel not painted-over, meaning those pixels will display
    the old color.

  • How to add an image in a JPanel

    Hi All,
    How to add an image in a JPanel and make it display.
    Thanks,

    I have tried with the below code. If I there is any fault please correct me.
    import java.awt.event.*;
    import java.awt.*;
    import javax.swing.*;
    public class HomePage extends JFrame implements     ActionListener {
        JButton cmdClick;
        JLabel label;
        JPanel homePanel = new JPanel();
        JPanel headPanel = new JPanel();
        JPanel btPanel = new JPanel();
        private JPanel mainPanel = new JPanel(new CardLayout());
        CardLayout cl;
        CalScenario calcFrame = null;
        public HomePage() {
           setTitle("Test Kit");
           setSize( 1008,399);
           setBackground( Color.gray );
           setResizable(false);
           Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
           Rectangle window = getBounds();
           setLocation((screen.width - window.width) / 2, (screen.height - window.height) / 2);
           setVisible(true);
            homePanel.setLayout(new BorderLayout());
            headPanel.setPreferredSize(new Dimension(1008,153));
            label = new JLabel("Main menu");
            headPanel.add(label);
            headPanel.setBackground(Color.CYAN);
            ImageIcon icon = new ImageIcon("images/slash.gif");
            JLabel imglabel = new JLabel();
            imglabel.setIcon(icon);
            headPanel.add(label);
            this.getContentPane().add(headPanel);
            btPanel.setBackground(Color.ORANGE);
            cmdClick = new JButton("Click here");
            btPanel.add(cmdClick);
            cmdClick.addActionListener(this);
            homePanel.add("North",headPanel);
            homePanel.add("West",btPanel);
            calcFrame = new CalScenario(mainPanel);
            mainPanel.add(homePanel, "HomePanel");
            mainPanel.add(calcFrame, "CalcFrame");
            cl = (CardLayout) (mainPanel.getLayout());
            add(mainPanel);
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        public void actionPerformed(ActionEvent source)  {
          if (source.getSource() == (JButton) cmdClick) {
                cl.show(mainPanel, "CalcFrame");
        public static void main( String args[]) {
             HomePage homeFrame = new HomePage();
             homeFrame.setVisible(true);
    }

  • Problem Displaying an Image in a JScrollPane

    Hi All,
    I've placed a Toolbar at the bottom of a JFrame and above the toolbar I placed a JTabbedPane. In one of the tabs I want to display a full sized image.The size of the image that I want to display using a scroll pane is 595x842 pixels. Now the problem is that when I display the image in the scroll pane the bottom toolbar is overlapped with the scrollpane. I don't want to resize the image as it is spoiling the image quality.I used the below code
    JPanel imagepagepanel=new JPanel()
        protected void paintComponent(Graphics g)
              js=new JScrollPane();
              Point p = js.getViewport().getViewPosition();
              g.drawImage(demoicon.getImage(), p.x, p.y, null);
    mytabbedpane.addTab("View Image",js); //add the scrollpane to the tabI even tried using a label to display the image in the tabbedpane and I've got the same overlapping problem.
    I am able to embed the default browser in my application using JDIC API and the image display is fine in the browser without overlapping the bottom toolbar. But I don't want to use a web browser to display the image.
    It would be of great help if anyone could suggest a solution to the overlapping problem. I want the scroll pane to work similar to a web browser while displaying a large sized image.
    Thanks in advance.

    Override the paintComponent method to just draw the
    image at 0, 0, w, h.
    The rest is not needed, to say the least.Here's an easier way
    import javax.imageio.ImageIO;
    import javax.swing.*;
    import java.awt.*;
    import java.io.File;
    import java.io.IOException;
    public class ImageInTabbedScrollTest extends JFrame {
        public ImageInTabbedScrollTest() {
            buildGUI();
        private void buildGUI() {
            JPanel mainPanel = (JPanel) getContentPane();
            mainPanel.setLayout(new BorderLayout());
            JTabbedPane tabbedPane = new JTabbedPane();
            try {
                Image image = ImageIO.read(new File("images/terrain.jpg"));
                ImageIcon icon = new ImageIcon(image);
                JLabel label = new JLabel(icon);
                JPanel panel = new JPanel(new GridLayout(0,1,5,5));
                panel.add(label);
                JScrollPane jsp = new JScrollPane(panel);
                tabbedPane.addTab("Image",jsp);
                JPanel anotherPanel = new JPanel();
                JLabel label2 = new JLabel("Second Panel");
                anotherPanel.add(label2);
                 label2.setFont(new Font("San Serif",Font.BOLD, 40));
                tabbedPane.add("Label",anotherPanel);
                mainPanel.add(tabbedPane, BorderLayout.CENTER);
                JToolBar tBar = new JToolBar();
                tBar.add(new Button("OK"));
                tBar.add(new Button("Maybe"));
                tBar.add(new Button("No"));
                mainPanel.add(tBar, BorderLayout.SOUTH);
                  } catch (IOException e) {
                e.printStackTrace();
        public static void main(String[] args) {
            Runnable runnable = new Runnable() {
                public void run() {
                    ImageInTabbedScrollTest testFrame = new ImageInTabbedScrollTest();
                    testFrame.setSize(new Dimension(600,600));
                    testFrame.setLocationRelativeTo(null);
                    testFrame.setDefaultCloseOperation(EXIT_ON_CLOSE);
                    testFrame.setVisible(true);
            SwingUtilities.invokeLater(runnable);
    }

  • Trouble using images on a jpanel

    Hi!
    First off, I'm new to java so don't shoot me for asking a probably dumb question! I've been searching for the past 2 hrs on how to add an image to my jpanel.....problem is I'm completely confussed! I've found how to add one to an applet, but then to be told adding to an application is different...i thought i'd figured it all out but it's still not working.
    I've declared the image....and tried adding it to a label....but it didnt work.
    I'm sooo confused and getting frustated, somebody please help!
    Thanks,
    JenanaBanana

    Hi,
    You should try searching over the forum before posting....
    Here is a link to a similar post in this forum...
    http://forum.java.sun.com/thread.jspa?threadID=550457&messageID=2688013
    And here is some clumsy code from myside. It works beautifully though:
    import java.awt.BorderLayout;
    import java.awt.FlowLayout;
    import javax.swing.ImageIcon;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    import javax.swing.SwingUtilities;
    import javax.swing.UIManager;
    public class ImagePanel {
    //Adding an image to a frame
    private static void addimage(JFrame aframe){
              //Create ImageIcon
              ImageIcon aimage = new ImageIcon("C:\\myimage.gif");
              //Create JPanel
              JPanel apanel = new JPanel(new FlowLayout());
              //Add mage to JPanel... you will need to do it through a JLabel to achieve this
              apanel.add(new JLabel(aimage));
              //Add the panel istself to the Frame
              aframe.getContentPane().add(apanel, BorderLayout.CENTER);
    //showpanel method
    private static void showpanel(){
              try{
                   //I like Windows Look And Feel
                   UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel" );
                   //Create a frame and set the Close operation.
                   JFrame myframe = new JFrame("Image on Panel");
                   myframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                   //add the image component to the frame
                   addimage(myframe);
                   //display
                   myframe.pack();
                   myframe.setVisible(true);
              catch(Exception e){
                   System.out.println("Application Error. Printing Stack Trace: ");
                   e.printStackTrace();
                   System.exit(-1);
    //Main Class
         public static void main(String[] args) {
              //Create Runnable mythread
              Runnable mythread = new Runnable() {
                   public void run() {
                        showpanel();
              //run it
              SwingUtilities.invokeLater(mythread);
    Let me know if any of this helps...
    Thanks,
    -Vamsi

  • How do you change the image in a JPanel?

    Hey! (firstly, i need to use image on a JPanel, label&icon not an option).
    I've made my JPanel class
        public class DrawingPanel extends JPanel {
            Image img;
            DrawingPanel() {
                Image img = Toolkit.getDefaultToolkit().getImage("13.jpg"); //default image at startup
            public void paintComponent (Graphics g) {
                super.paintComponent (g);
                // Use the image width & height to find the starting point
                int imgX = getSize ().width/2 - img.getWidth (this);
                int imgY = getSize ().height/2 - img.getHeight (this);
                //Draw image centered in the middle of the panel   
                g.drawImage (img, 0, 0, this);
            } // paintComponent
        } // DrawingPanelAnd I've made my instance of it and added it to the Frame:
        DrawingPanel imagePanel = new DrawingPanel();Now, I need to change the image on the JPanel according to the user's input. I have the string of the location of the new image. How do I update the JPanel to display this new image? Any help greatly appreciated!!

    Well... You could just add a method in your class which sets the image according to the new image name you provided. Something like this:
        public class DrawingPanel extends JPanel {
            Image img;
            DrawingPanel() {
                img = Toolkit.getDefaultToolkit().getImage("13.jpg"); //default image at startup
            public void setImage(String imageName) {
                    img = Toolkit.getDefaultToolkit().getImage(imageName); //Loading the desired image
            public void paintComponent (Graphics g) {
                super.paintComponent (g);
                // Use the image width & height to find the starting point
                int imgX = getSize ().width/2 - img.getWidth (this);
                int imgY = getSize ().height/2 - img.getHeight (this);
                //Draw image centered in the middle of the panel   
                g.drawImage (img, 0, 0, this);
            } // paintComponent
        } // DrawingPanel

  • Problem displaying the image

    I am having a trouble with display an image. My image is put in the base directory of my workspace and my IDE is Eclipse. However, I just can't get the image to display...
    It is at the bottom of the code...
    package ca.carleton.comp3004.client.ui;
    import java.awt.BorderLayout;
    import java.awt.Graphics;
    import java.awt.Image;
    import java.awt.event.ActionEvent;
    import javax.imageio.*;
    import javax.swing.AbstractAction;
    import javax.swing.Action;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    import javax.swing.JScrollPane;
    import javax.swing.JTextArea;
    import javax.swing.JTextField;
    import javax.swing.border.TitledBorder;
    import javax.swing.*;
    import java.awt.*;
    import javax.swing.event.*;
    import java.awt.event.*;
    import java.io.File;
    import java.io.IOException;
    import ca.carleton.comp3004.client.model.Model;
    import ca.carleton.comp3004.util.AppUtils;
    import ca.carleton.comp3004.util.UiUtils;
    public class GamePanel extends JPanel
         private JPanel bottomStuff;
         private JScrollPane cardPane;
         private JButton requestCards;
         private JPanel centerStuff;
         private JPanel[] playerStuff;
         private JLabel[] playerName;
         private JLabel[] playerNumCards;
         private JLabel[] playerScore;
         private JPanel topStuff;
         private JLabel unoCode;
         private JLabel timeLabel;
         private JButton leave;
         private Image board = null;
         //Icon BoardImage = new ImageIcon("C:\Users\tzaid\Desktop\steve stuff\Johnny_Workspace\GameBoard.png");
         //private ActionListener buttonlistener;
         private Model model;
         private class CardRequestListener implements ActionListener {
            public void actionPerformed(ActionEvent theEvent) {
                  AppUtils.invoke(new Runnable()
                     public void run()
                          model.requestCards();
         private class CardButtontListener implements ActionListener {
            public void actionPerformed(ActionEvent theEvent) {
                 final int cardIndex = Integer.parseInt(theEvent.getActionCommand());
                 AppUtils.invoke(new Runnable()
                    public void run()
                         model.playCard(cardIndex); //****note: extract cardNum
         private class LeaveListener implements ActionListener {
            public void actionPerformed(ActionEvent theEvent) {
                 AppUtils.invoke(new Runnable()
                    public void run()
                         model.leave(); //****note: not in protocol yet
         // actions
         CardRequestListener myCardRequestListener = new CardRequestListener();
         CardButtontListener myCardButtonListener = new CardButtontListener();
         LeaveListener myLeaveListener = new LeaveListener();
        public GamePanel(Model model)
             this.model = model;
             createComponents(this);
         * Creates the components.
        private void createComponents(JPanel container)
             container.setLayout(new BorderLayout());
            // chat panel
            CreatePanels();
            container.add(centerStuff, BorderLayout.CENTER);
            container.add(bottomStuff, BorderLayout.SOUTH);
            container.add(topStuff, BorderLayout.NORTH);
          //  Graphics g = new Graphics();
          //  g.drawImage(board, 0, 0, null);
         * Creates the chat panel for chat room functionality.
         * @return A panel containing chat room controls.
         * @see JPanel
        private void CreatePanels()
             topStuff = new JPanel();
             unoCode = new JLabel("UNO Code: ");
             timeLabel = new JLabel("Time: ");
             leave = new JButton("Leave Game");
             leave.addActionListener(myLeaveListener);
             topStuff.setLayout(new BorderLayout());
             topStuff.add(unoCode, BorderLayout.WEST);
             topStuff.add(timeLabel, BorderLayout.EAST);
             topStuff.add(leave, BorderLayout.NORTH);
             topStuff.setBorder(BorderFactory.createLineBorder(Color.black));
             //******note: need to specify size*****
             int size = 5;
             centerStuff = new JPanel();
             playerStuff = new JPanel[size];
             playerName = new JLabel[size];
             playerNumCards = new JLabel[size];
             playerScore = new JLabel[size];
             centerStuff.setLayout(new FlowLayout(FlowLayout.CENTER, 40, 40));  //need to change later so is around table
             for(int i = 0; i<size; i++){
                  playerStuff[i] = new JPanel();
                  playerStuff.setLayout(new BorderLayout());
              playerName[i] = new JLabel("no name" ); //****get player name here
              playerNumCards[i] = new JLabel("0");
              playerScore[i] = new JLabel("0");
              playerStuff[i].add(playerName[i], BorderLayout.NORTH);
              playerStuff[i].add(playerNumCards[i], BorderLayout.CENTER);
              playerStuff[i].add(playerScore[i], BorderLayout.SOUTH);
              playerStuff[i].setBorder(BorderFactory.createLineBorder(Color.black));
              centerStuff.add(playerStuff[i]);
         bottomStuff = new JPanel();
         cardPane = new JScrollPane();
         requestCards = new JButton("Request Cards");
         requestCards.addActionListener(myCardRequestListener);
         bottomStuff.setLayout(new BorderLayout());
         bottomStuff.add(requestCards, BorderLayout.WEST);
         bottomStuff.add(cardPane, BorderLayout.CENTER);
         bottomStuff.setBorder(BorderFactory.createLineBorder(Color.black));
    public GamePanel()
         setPreferredSize(new Dimension(790,572));
         setMaximumSize(getPreferredSize());
         setMinimumSize(getPreferredSize());
         setSize(getPreferredSize());
         try
    board= ImageIO.read(new File("GameBoard.png"));
    getGraphics().drawImage(board, 0, 0, null);
         catch (IOException e)
         e.printStackTrace();
    /* private JPanel createMessageListPanel()
    JPanel messageListPanel = new JPanel(new BorderLayout());
    JScrollPane scrollPane = new JScrollPane(messageList = createMessageList(),
    JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
    JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
    scrollPane.setAutoscrolls(true);
    messageListPanel.add(scrollPane);
    messageListPanel.setBorder(new TitledBorder("Messages"));
    return messageListPanel;
    * Creates message list.
    * @return A text area to store messages in.

    Look like a bad video card. Are you eligible for Apple's Repair extension programs?

  • Displaying an image part 2

    Hi,
    I'm trying to do a very simple task which is just to display an image in a JFrame. But, I can't do it!!! Please help me, with what import statements i need and nething else for this simple thing. I looked at the swing tutorial, but it didn' seem to give me a precise answer, yet it confused me with something called ImageIcon?? Please help!!! How do I display an image in a Jframe???? (image is saved in the same place as the file) What code would i write in the following code given and where, to display a pic??
    //SSPanesar
    //copyright 2005 all rights reserved
    import java.awt.*;
    import java.awt.geom.*;
    import javax.swing.*;
    //For buttons
    import javax.swing.AbstractButton;
    import javax.swing.JButton;
    import javax.swing.JPanel;
    import javax.swing.JFrame;
    import javax.swing.ImageIcon;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.awt.event.KeyEvent;
    public class WindowOnly extends JFrame
    public WindowOnly()
    setBackground(Color.pink);
    public void paint (Graphics g) // allows the background color to be applied.
    Graphics2D g2 = (Graphics2D)g;
    public void paintWindowOnly()
    JFrame myFrame = new WindowOnly();
    myFrame.setSize (900,650);
    myFrame.show();
    public static void main (String[] args)
    WindowOnly myWindow = new WindowOnly();
    myWindow.paintWindowOnly();
    }

    Ok, it seems to have worked, thanks very much for ur help. I know my Java's weak but its something i wanna gte good at. I appreciate ur help. Was wondering, Is it possible to have u direct email pls? In cases i ur not here in the forum?

Maybe you are looking for

  • Solaris 10 x86 on UCS

    Has anyone done any installs with Solaris 10 x86 on UCS B-series yet? If so, anything worth paying attention to? I have a request from a customer to put Solaris 10 on UCS and up until now I was not aware that Solaris will be supported on UCS until so

  • SQL 92 Outer Join Syntax and Funtion.

    When i am trying to use {fn substring(..)} or {oj table} in sql query to make it database independent, oralce driver does not support this. Could any one explain the above issue? If so, How do i use it? Explain the syntax a bit. Thanks in Advance, Ra

  • How to install Safari 3.2 to replace Safari 4?

    In an effort to regain URL Snapback, I've tried to reinstall Safari 3.2 on both my Leopard MBP and my wife's Tiger MBP, but when I get to the location page, my internal drive is disallowed. I tried putting Safari 4 in the trash, along with all of its

  • Weblogic.jndi.WLContext.PIN_TO_PRIMARY_SERVER  == "true"  not helping...

              Hi,           In cluster there are 2 NT boxes. All beans are deployed           evenly on both the machines. m/c A session bean SB1 is doing           lookup for the same session bean SB1 on m/c 2.           The problem is it's getting the

  • What is the best way to download audio files?

    I am building a website for a church.  How do I put the weekly audio sermons on the site, so that the files don't take forever to download? I had a link with quicktime, but someone said they didn't have that plug-in, so I have embedded the files. ...