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

Similar Messages

  • How to place an image in database and how to retrieve and display it in the front end

    how to place an image in database and how to retrieve and display it in the front end
    and to place an image in database and retrieve the image from database using xml
    please,help me out.

    Create a table with a Long RAW Datatype column for storing the Image Column Data.
    Create the form based on the table , which by defaults the column with LONG RAW atatype to a Image Item.
    You can use Forms Built in function READ_IMAGE_FILE to read a Image file stored on the file system in to the image item.
    A save on the form saves the image in the Image item in the long raw column.

  • How to place the images in Indesign xml file by Javascript?

    How to place the images in Indesign xml file by Javascript?
    We got the Indesign xml file, how to give the image placement link by Indesign javascript? Please help me its urgent.

    Hi,
    You can pass the image url as a href attribute=> file:///Users/me/Documents/my_pic.jpg directly within your xml. It just needs that you pass a local, static and valid url.
    If you want to add image later once the xml is flowed and so target specific nodes and inject images, it's a bit more complex. If the node is not part of the layout, you may try to reach the XMLElement objet and such an attribute, then layout the element.
    var x = some XMLElement
    x.xmlAttributes.add("href","file:///Users/m/Documents/my_pic.jpg" );
    If already placed, then you have to get the associated pageItem, then place your file into it.
    pagItm.place ( File ( "/Users/m/Documents/my_pic.jpg" ) );
    Hope that helps,
    Loic
    http://www.loicaigon.com

  • How to place multiple images?

    Hi,
    How to place multiple images?
    Regards,
    Learner

    Is the script creating the frames? If so, just assign each frame a
    variable, or make them all into an array. Then use something like:
    myFrame.place("aFile");
    If the script is not creating the frame, then are they live frames on
    the page, or are they actually on a master page?
    If they're on master spreads, you'll have to release them to the page
    you want. (I think it's myMasterFrame.override(myPage) where myPage is
    the live page you want to detach them on, but you'll have to double
    check that.)
    But presuming they're regular detached frames on a page, if you want
    your script to figure out which is the first and which is the second you
    can either use script labels in the UI and then search for the script
    label, or else you'll have to write a function that will get all
    rectangles on the page (myPage.rectangles.everyItem().getElements() and
    either do a clever javascript sort, or write a straightforward function
    to sort them by height and x-pos.
    Hope that sheds some light on the task ahead!
    Ariel

  • How to place a image in a page?

    pls anyone guide me? how to place a image in a page?
    thanks,
    screen410099

    Take a look at the code found in this function:
    SDKLayoutHelper::PlaceFileInFrame
    As expected you can find it in the SDKLayoutHelper file usually found in the Common folder of the SDK.  Anyway it has an example of one way of achieving your goal.
    There are other ways as well.  Here is some code from one of my plugins which uses the LoadPlaceGunCmd boss:
              PMRect pRC = itemGeometry -> GetPathBoundingBox(InnerToPasteboardMatrix(pParentTransform));;
              // Create an ImportCmd:
              InterfacePtr<ICommand> importAndLoadPlaceGunCmd(CmdUtils::CreateCommand(kImportAndLoadPlaceGunCmdBoss));
              //InterfacePtr<ICommand> importAndLoadPlaceGunCmd(CmdUtils::CreateCommand(kImportFileCmdBoss));
              if (importAndLoadPlaceGunCmd == nil)
                  ASSERT_FAIL("importAndLoadPlaceGunCmd invalid");
                  break;
                URI URIPath;
                URIUTILS -> IDFileToURI(path, URIPath);
              // Set the IImportResourceCmdData Interface's data:
              InterfacePtr<IImportResourceCmdData> importFileCmdData(importAndLoadPlaceGunCmd, IID_IIMPORTRESOURCECMDDATA);
              if (importFileCmdData == nil)
                  ASSERT_FAIL("importFileCmdData invalid");
                  break;
              importFileCmdData -> Set(db, URIPath, (K2::UIFlags)0, kTrue, kFalse);
              ErrorCode status = CmdUtils::ProcessCommand(importAndLoadPlaceGunCmd);
              const UIDList* imageList = importAndLoadPlaceGunCmd -> GetItemList();
              if (!imageList || imageList -> Length() == 0)
                  break;
              UIDRef imageFrame = imageList -> GetRef(0);
              InterfacePtr<IHierarchy> imageFrameHierarchy(imageFrame, UseDefaultIID());
              UIDRef newImage(db, imageFrameHierarchy -> GetChildUID(0));
              imageFrameHierarchy -> Remove(imageFrameHierarchy -> GetChildUID(0));
              // Create an placeGraphicCmd:
              InterfacePtr<ICommand> placeGraphicCmd(CmdUtils::CreateCommand(kPlaceItemInGraphicFrameCmdBoss));
              if (placeGraphicCmd == nil)
                  ASSERT_FAIL("placeGraphicCmd invalid");
                  break;
              placeGraphicCmd -> SetItemList(UIDList(newImage));
              // Set the IPlacePIData Interface's data:
              InterfacePtr<IPlacePIData> placePIData(placeGraphicCmd, IID_IPLACEPIDATA);
              if (placePIData == nil)
                  ASSERT_FAIL("placePIData invalid");
                  break;
              placePIData -> Set(pageItemRef, nil, kFalse);
              // Process the ImportAndPlaceCmd:
              status = CmdUtils::ProcessCommand(placeGraphicCmd);
    HTH.
    John

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

  • How to place an image on the dashboard in obiee 11.1.1.5  version

    Hi All,
    I am using obiee 11.1.1.5.I want to place an image on the dashboard.Can anyone help me on how to achieve this.
    Thanks,
    Praful

    Hi,
    In OBIEE 11g, an image needs to be placed in two locations. They are
    1. Middleware_Home\Oracle_BI1\bifoundation\web\app\res\your_skin\images
    Example: D:\OBI11g\Oracle_BI1\bifoundation\web\app\res\s_blafp\images
    2. Middleware_Home\user_projects\domains\bifoundation_domain\servers\bi_server1\tmp\_WL_user\analytics_11.1.1\7dezjl\war\res\your_skin\images
    Example: D:\OBI11g\user_projects\domains\bifoundation_domain\servers\bi_server1\tmp\_WL_user\analytics_11.1.1\7dezjl\war\res\s_blafp\images
    PS: In the above example s_blafp skin is used.
    Usage of the newely added image in a Title View:
    res/s_blafp/images/new_image.jpg
    Award points it is useful.
    Thanks,
    satya

  • How To place two images in a obiee 11g Report Page header

    Hi ,
    Greetings for the day!.
    I want to place two images (one at top left and another at top right ) above the table view . I am not sure how it is called as. i think it is page header . Can anyone let me know how to accomplish this ?
    Kind Regards
    Sudarshan

    Hi,
    Will you pls let me know the best pixel size can be given for both images ?
    Also how can i make the images left and right aligned .Formatting option is not allowing to move the images left or right.
    Pdf output of the report header should display images one at extreme left and extreme right.
    Will you pls let me know whether i can try in single view(title/static/narrative) with html code like below :
    <img src="smiley.gif" alt="Smiley face" align="middle" />
    If so pls provide the details.

  • How to place multiple images in batch with drop shadow effects on room backgrounds at the same position?

    I want to place multiple images of hand paintings with drop shadow effects on room backgrounds to make them look as if the paintings are hanged on the room walls. I know how to do it one by one, but that takes time and I want to do it in batch at once.
    I am quite a beginner for adobe photoshop CS6. I belive such an automated task is possible through 'Automated Batch' function and/or 'Create Droplet' function. Kindly share your expert opinion.

    If you want to go with Batch I would recommend creating an Action of more or less these steps:
    • set the resolution to the same as the background image’s
    • change the image from Background Layer to regular Layer if necessary
    • convert it to a Smart Object
    • add a Drop Shadow Layer Style to the image (do not use Global Angle)
    • place the background image (File > Place …)
    • move it behind the image layer
    • Image > Reveal All
    • make Selection from that layer’s transparency (cmd-click its icon in the Layers Panel) and use Image > Crop
    • select and transform the image layer to fit the intended position
    This would naturally work out best if the images had the same size and proportions.
    For the reflection on the floor duplicate the image, flip it vertically, move it in position and reduce its opacity to maybe 10%.
    Realistically you may have to hide it partially behind the pillows, a Vector Mask would be an option.

  • How to place multiple images of hand paintings with drop shadow effects on room backgrounds?

    I want to place multiple images of hand paintings with drop shadow effects on room backgrounds to make them look as if the paintings are hanged on the room walls. I know how to do it one by one, but that takes time and I want to do it in batch at once.
    I am quite a beginner for adobe photoshop CS6. I belive such an automated task is possible through 'Automated Batch' function and/or 'Create Droplet' function. Kindly share your expert opinion.

    If you want to go with Batch I would recommend creating an Action of more or less these steps:
    • set the resolution to the same as the background image’s
    • change the image from Background Layer to regular Layer if necessary
    • convert it to a Smart Object
    • add a Drop Shadow Layer Style to the image (do not use Global Angle)
    • place the background image (File > Place …)
    • move it behind the image layer
    • Image > Reveal All
    • make Selection from that layer’s transparency (cmd-click its icon in the Layers Panel) and use Image > Crop
    • select and transform the image layer to fit the intended position
    This would naturally work out best if the images had the same size and proportions.
    For the reflection on the floor duplicate the image, flip it vertically, move it in position and reduce its opacity to maybe 10%.
    Realistically you may have to hide it partially behind the pillows, a Vector Mask would be an option.

  • How to place an image onto each page

    Hi !
    How do I place an image onto each page (like a logo in a sidebar) using Pages 5.5 ?
    Thanks,
    Karsten

    Karsten,
    I am surprised no one has answered you yet - there are so many Pages users here.
    I am not a Pages user but I did find one way here on this thread in an answer from Arno Jannarelly
    insert image to header in Pages, template header
    "If you want any layout item to be repeated to all of the pages of your document, you just have to select the item(s), then go to Arrange/Section Masters/Move Object to Section Master.
    The good thing of this is that you can repeat any item or group of items placed anywhere you want on the page."
    Now when I first tried it I had no luck, until I selected the image and went to Arrange > Section Masters from the main menu, not on the right hand side from the Format/Document area.  
    From there there is an option: Move Object to Section Master.
    You then can format your image with drop shadows, opacity, etc. and it should be there on new pages in Pages. 

  • How to place raster images as smart objects?

    I'm trying to duplicate Photoshop's File:Place menu functionality and I'm experiencing something that I can't figure out. (I've added my code to the end of this message.)
    I have a variety of test EPS images that I can run through the File:Place menu. They all appear on the document as "Smart Objects". That is I can then do a bunch of transforms to the image (like rotate, move, deform) before committing to the image to the document.
    The important point here is that some images, when opened by Photoshop, first ask that I "Rasterize EPS Format" while others just open up without comment.
    While doing these File:Place actions, I've been using the Listener plugin that comes with the SDK to generate code dumps of my actions. From these I've then generated my own code for placing images onto a document. I've had to re-arrange the code a bit to work in Objective-C so there's a good chance that I've done something wrong while translating.
    Now if you look at my code you notice a commented out section. If you uncomment those lines then you basically have what I got from the Listener plugin log. But the problem is that this code then doesn't act like the File:Place menu action. It creates a new layer, places the image on the page - but its gone one step too far and the image is no longer a "Smart Object". The image is committed to the layer.
    With a bit of experimenting I commented out the line that you can see commented out in my code. However, this does something odd. For all images you can see Photoshop put up a busy icon for a few seconds showing that it is process, but only images that Photoshop wants to "Rasterize EPS Format" actually appear on the page as Smart Objects. Trying to place the images that Photoshop doesn't rasterize results in nothing appearing.
    That's my problem. If I uncomment that line in my code then all images that I test with appear on the page - but not as Smart Objects. If I comment out the code then only images that Photoshop wants to rasterize appear - but those that do appear then appear as Smart Objects.
    So that's my goal: to place any image onto a document as a Smart Object just like Photoshop's File:Place menu command does. Any ideas where I'm going wrong?
    - (SPErr)photoshopPlayeventPlace:(char *)cPath
    PIActionDescriptor result = NULL;
    Auto_Desc descriptor;
    Auto_Desc offsetDetails;
    SPErr error = kSPNoError;
    Handle aliasValue = NULL;
    FullPathToAlias(cPath, aliasValue);
    do
    error = sPSActionDescriptor->PutAlias(descriptor.get(), keyNull, aliasValue);
    if (error) break;
    // error = sPSActionDescriptor->PutEnumerated(descriptor.get(), keyFreeTransformCenterState, typeQuadCenterState, enumQCSAverage);
    // if (error) break;
    error = sPSActionDescriptor->PutUnitFloat(offsetDetails.get(), keyHorizontal, unitDistance, 0);
    if (error) break;
    error = sPSActionDescriptor->PutUnitFloat(offsetDetails.get(), keyVertical, unitDistance, 0);
    if (error) break;
    error = sPSActionDescriptor->PutObject(descriptor.get(), keyOffset, classOffset, offsetDetails.get());
    if (error) break;
    error = sPSActionControl->Play(&result, eventPlace, descriptor.get(), plugInDialogSilent);
    if (error) break;
    while (false);
    if (result != NULL) sPSActionDescriptor->Free(result);
    if (aliasValue != NULL) sPSHandle->Dispose(aliasValue);
    return error;

    If you want to go with Batch I would recommend creating an Action of more or less these steps:
    • set the resolution to the same as the background image’s
    • change the image from Background Layer to regular Layer if necessary
    • convert it to a Smart Object
    • add a Drop Shadow Layer Style to the image (do not use Global Angle)
    • place the background image (File > Place …)
    • move it behind the image layer
    • Image > Reveal All
    • make Selection from that layer’s transparency (cmd-click its icon in the Layers Panel) and use Image > Crop
    • select and transform the image layer to fit the intended position
    This would naturally work out best if the images had the same size and proportions.
    For the reflection on the floor duplicate the image, flip it vertically, move it in position and reduce its opacity to maybe 10%.
    Realistically you may have to hide it partially behind the pillows, a Vector Mask would be an option.

  • How to place an image created with DefineBitsJPEG2?

    We are writing software that generates native SWF's in binary.
    We define a simple JPEG image using DefineBitsJPEG2.
    When we try to place the character using PlaceObject2 and a simple scaling matrix.
    The swf renders completely blank.
    My question is:
    Is it possible to place the image directly using PlaceObject2 or do you need to generate a shape first and use the bitmap as a fill style?
    The spec leads me to beleive direct placement should be possible. However I have not seen any examples to prove it.
    I've opened the SWF with a decompiler and the image appears to be valid. SWF is not corrupt to my knowledge.
    I've included the generated SWF in question as an attachment.
    Thanks for the help!
    Mike M.

    Solved this a few week ago by generating a shape and then using the image bitmap as a fill style for the shape.
    This seems like more work than should be necessary...but it works!

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

  • How to place SVG image in web page?

    Attempting to use an SVG image for first time, saved out of
    Illustrator CS3. When I try to place it on a web page in
    Dreamweaver CS3, .svg file is greyed out. Dragging it onto page in
    design view just makes a text link to the image, that has to be
    clicked to display the SVG. What I really want to do is use SVG
    file as a background image (800 x 600 px) that scales to fill
    browser window - is that possible?
    System: Mac OS X 10.4.11

    There is no reliable way to size an 800 x 600 background
    image up or down
    according to viewport size. You could center the page. Thus
    your BG image
    would move to center with page color appearing on either side
    on wider
    displays.
    800 x 600 background image is quite large by web standards.
    Most web
    designers prefer to use small images or slices and then tile
    or repeat them
    horizontally and/or vertically.
    Examples here:
    http://alt-web.com/Backgrounds.shtml
    --Nancy O.
    Alt-Web Design & Publishing
    www.alt-web.com
    "driprint" <[email protected]> wrote in
    message
    news:fsk89k$e83$[email protected]..
    > Attempting to use an SVG image for first time, saved out
    of Illustrator
    CS3.
    > When I try to place it on a web page in Dreamweaver CS3,
    .svg file is
    greyed
    > out. Dragging it onto page in design view just makes a
    text link to the
    image,
    > that has to be clicked to display the SVG. What I really
    want to do is use
    SVG
    > file as a background image (800 x 600 px) that scales to
    fill browser
    window -
    > is that possible?
    > System: Mac OS X 10.4.11
    >
    >
    >

Maybe you are looking for

  • Hooking up MacBook to 50" Panasonic Plasma?

    I am using the Apple mini-dvi to vga adapter along with a 6' vga cable to hook up my macbook to my 50" panasonic plasma (full specs: http://www.circuitcity.com/ssm/Specifications-of-Panasonic-50-Plasma-HDTV-TH-50P Z700U/sem/rpsm/oid/175537/rpem/ccd/p

  • Can't transfer my ipod tunes to my laptop

    Hi all, just bought a macbook pro, and i took my ipod to put some tunes on it. but it won't let me transfer any of my tunes to my computer! what gives??!?!?!?!

  • Same positions with different hr department...?

    Assalam o Alikum I am facing a scenario of same position in many department. The organization is a fertilizer company and at plant site they have many departments which contain same position. For example Position: Supervisor (Mechanical) Department:

  • How do I trim the end off my Final Cut Pro X timeline?

    When I did my rough, rough cut, my timeline was 10 minutes long. I have since edited my video down to five minutes. Now I have five minutes of dead space trailing my five minute video. How do I snip those five minutes off the end?

  • LIV posting for exch. rate due to GR

    Hi, During GR for a foreign curr(FC) against local curr(LC), the entry is : DR Expense   FC$100   LC$200 CR GR           FC$100   LC$200 During LIV, the following entry are posted : CR Vendor      FC$100  LC$180 DR GR            FC$100  LC$200 CR Exp