How to set a jpg image ContentType of JEditorPane

Hi how can i display an image on a JEditorPane like image.jpg?
I tried myEditor.setContentType("image/jpeg") but it still displays characters instead of the image.
import java.awt.*;
import javax.swing.*;
import java.io.*;
public class Pagina extends JFrame implements Runnable {
     JEditorPane e;
     public Pagina(){
          super("fds");
          e = new JEditorPane();
          e.setEditable(false);
          e.setContentType("image/jpeg");
          Container c = getContentPane();
          c.add(e);
          setSize(400,400);
          setVisible(true);
          Thread t = new Thread(this);
          t.start();
     public void run(){
          while(true){
               try{
               e.setPage( "http://10.0.0.5/SnapShot.jpg" );
               Thread.sleep(1000);
          catch(IOException ioe){}
          catch(InterruptedException ie){}
     public static void main (String [] args) {
          new Pagina();
}

In your current app, you are trying to redisplay an image in some infinite loop. This smells bad to me. I am no expert in java graphics, far from it, but if you want to paint a background image within a JEditorPane, since JEditorPane is a component and has to paint itself, you could override its paintComponent method and draw an image inside there using the Graphics object.
another way is to put the JEditorPane on top of a JPanel that draws your picture. In both instances, I think that you'll need to set the JEditorPane's opaqueness to "false".
Something like so, perhaps?
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.net.URL;
import javax.imageio.ImageIO;
import javax.swing.BorderFactory;
import javax.swing.JEditorPane;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
class ImageJEditorPane extends JPanel
    private static final String IMAGE_FILE1 = "disc/d1/f/image1.jpg";   
    private static final String IMAGE_URL = "http://10.0.0.5/SnapShot.jpg";
    private BufferedImage myImage = null;
    private JEditorPane editorPane;
    ImageJEditorPane()
        try
            setPreferredSize(new Dimension(800, 650));
            setBorder(BorderFactory.createEmptyBorder(15, 15, 15, 15));
            setLayout(new BorderLayout());
            //myImage = ImageIO.read(new File(IMAGE_FILE1));
            myImage = ImageIO.read(new URL(IMAGE_URL));
            editorPane = new JEditorPane()
                @Override
                protected void paintComponent(Graphics g)
                    g.drawImage(myImage, 0, 0, null);
                    super.paintComponent(g);
            editorPane.setPreferredSize(new Dimension(1200, 1000));
            editorPane.setOpaque(false);
            JScrollPane scrollPane = new JScrollPane(editorPane);
            add(scrollPane, BorderLayout.CENTER);
        catch (IOException e)
            e.printStackTrace();
     //or you could do it this way
    protected void paintComponent(Graphics g)
        super.paintComponent(g);
        g.drawImage(myImage, 0, 0, null);
    private static void createAndShowGUI()
        JFrame frame = new JFrame("ImageJEditorPane Application");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.getContentPane().add(new ImageJEditorPane());
        frame.pack();
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
    public static void main(String[] args)
        javax.swing.SwingUtilities.invokeLater(new Runnable()
            public void run()
                createAndShowGUI();
}Edited by: Encephalopathic on Dec 21, 2007 3:09 PM

Similar Messages

  • How do I transfer jpg images transfered to an SD card, into an iPad?

    How do I transfer jpg images transfered to an SD card, into an iPad? Have tried lots - nothing works.
    I would like to buy an iPad if this could be solved.
    I am on a PC
    I have iTunes on my desptop, not my laptop.
    When traveling I shoot RAW 22mg photos.
    I resize down to 2mg file for screen.
    I transfer to SD card to then transfer to an iPad.
    I use wifes new iPad with SD card accessory to try to get it to work but it doesn't.
    I created a test directory with subdirectories
    Synced it to iPhone 3GS and worked fine.
    Will not do syncing from laptop because ...no iTunes anddon't want it on laptop.
    Did experiment with wife's MAC desktop - it worked fine
    Card is an SD HC which supposedly works fine.
    Apple would have a customer if I could do this.
    Thanks for any possible solutions.
    Brad

    Meg:
    So far you are leading the race. I tried more scenarios on the SD card and the DCIM + names no longer than 8 characters works. However this naming and sorting convention still falls short for me. I realize what we want and what we get are sometimes two different things and I always try to seek a workaround.
    If I breakdown and install iTunes on my laptop and sync just my main directory with many longer than 8 chars sub directory names and within those many jpg's with longer than 8 chars names would that solve my dilemma?...like how it works on the iPhone?
    On the recent test with the SD attachment the sub directories did not import or even show - only those in the root. I named one sub directory with only 8 chars and one file inside less than 8 chars - not found by iPad.
    I am hesitant to do this (add iTunes to laptop) because I may not necessarily want all files synced on desktop, laptop and iPad.
    I sort many files based on events and travel days and most of the events I do are several days, hence many subdirectories...sometimes 5 weeks gone.
    Sorry to be a pain but I am trying to buy an iPad...but so far not practical reason.
    Brad

  • How to open a .jpg image and edit it.

    I can't seem to figure out how to open a .jpg image or any image in Flash Professional CC. I'm quite new to this so sorry if this sounds like a stupid question. When I go to File>Open I can only see .as , .fla, .jsfl , .xsfl and .xml files. I do not have an option to be able to view .jpg or .png pictures. I would appericate if somebody could take the time and answer this for me
    Thanks

    If you want to edit a jpeg or png image, do that with a separate program such as Fireworks or Photoshop.  After you import the image into Flash you can edit the image again in these separate applications and update the image you imported into Flash via selecting the Properties option in the library menu for the image and clicking the Update button.

  • Premier pro cs6: how to use 400 jpg images to make a movie?

    I want to use about 400 jpg images to make a movie.  is there a way to add them to a sequence in a random order?

    I'm not aware of a randomize feature either, but here is a suggested workflow that may make it easier than shuffling 400 images around in Premiere:
    Open your images in Bridge
    Move them around to meet your random requirement
    Highlight all images (Ctrl-A)
    Right-click / batch rename and add a sequence number to the front of each name (I like to add a text "_" too) and copy the resulting set of images to an empty directory
    Import the whole directory into Premiere
    Automate to timeline
    I used to use Liquid and it had a wonderful freestyle way to pre-order your clips or images prior to dumping them onto your timeline, and the above workflow is how I have come to approximate the same.
    Regards,
    Jim

  • How to set a background image to fill the entire screen on any device in a spark mobile application

    Hi,
    I started developing a mobile application with Flex.
    I'm trying to set a background image to fill the whole screen. I've been stucked at this point for days now. I tried everything and no solution seems to work for me.
    I'm using a TabbedViewNavigatorApplication and i need to set some background images on views.
    I need my image to fill the entire screen on any device. i don't need to mantain image aspect ratio,  just need it to be fullscreen. This seemed to work when setting a custom skin on the TabbedViewNavigatorApplication, however this blocked all my views for some reason and all components contained in view became invisible.
    Can you please tell me how can i achieve this?
    Kind regards,
    Dan

    Basically you need a larger image which can accommodate any device. The trick is to show only what each device can display, so therefore some clipping will occur based on device. Have something centered and towards margins have a  gradient or just plane colors that way the stuff in the middle will be visible on every device while nobody will care if you are clipping from the color fill.
    C

  • How to set a background image in Web dynpro for Java?

    Hi,
    Experts,
    As i  want to set a background image in my application can u please suggest how to get background image. send any sample scenarios.
    Thanks in advance,
    Shabeer ahmed

    Hi,
    I don't  think it can be done in WDJ.
    Maybe something can be done on the portal end.
    Refer to http://help.sap.com/saphelp_nw70/helpdata/en/79/affe402a5ff223e10000000a155106/frameset.htm
    Changing the theme can help maybe but I do not know how to go about that
    Regards,
    Himanshu

  • Simple question: How to set a different image to each side of a 3D cube?

    Hi all,
    I'm very new in the use of Java 3D and I would like to know how to set, in a 3D cube, for each side a different image.
    Currently I've the code to set an image as texture of the cube, but it applies the same image to all the sides. However, I would like to use different images for each side.
    This is my code: http://pastebin.com/sexBx57K
    Any clue?
    Thanks!

    I think I worked it out.
    I just have to set the JAXP parser
    Q. How do I use a different JAXP compatible implementation?
    The JAXP 1.1 API allows applications to plug in different JAXP compatible implementations of parsers or XSLT processors. For example, when an application wants to create a new JAXP DocumentBuilderFactory instance, it calls the staic method DocumentBuilderFactory.newInstance(). This causes a search for the name of a concrete subclass of DocumentBuilderFactory using the following order:
    1. The value of a system property like javax.xml.parsers.DocumentBuilderFactory if it exists and is accessible.
    2. The contents of the file $JAVA_HOME/jre/lib/jaxp.properties if it exists.
    3. The Jar Service Provider discovery mechanism specified in the Jar File Specification. A jar file can have a resource (i.e. an embedded file) such as META-INF/services/javax.xml.parsers.DocumentBuilderFactory containing the name of the concrete class to instantiate.
    4. The fallback platform default implementation.

  • Please guide how to set the mask image

    Hi All,
    i want to set camera images as a background of greeting image( those already in .png formate with white color background ), so when i am trying with following code in my app it is showing the color image in black and white color .
    Please guide me how it is work.
    I am using following code
    -(UIImage)maskImage:(UIImage)image withMask:(UIImage*)mask {
    CGImageRef imgRef = image CGImage;
    CGImageRef maskRef = mask CGImage;
    CGImageRef actualMask = CGImageMaskCreate(CGImageGetWidth(maskRef),
    CGImageGetHeight(maskRef),
    CGImageGetBitsPerComponent(maskRef),
    CGImageGetBitsPerPixel(maskRef),
    CGImageGetBytesPerRow(maskRef),
    CGImageGetDataProvider(maskRef), NULL, false);
    CGImageRef masked = CGImageCreateWithMask(imgRef, actualMask);
    return UIImage imageWithCGImage:masked;
    }

    Hi,
    Thank you for the reply.
    My problem is related to Oracle Forms. So I go on Help ->Diagnostics ->custom code -> personalize. There I choose my field and PROMPT_TEXT property. But I do not know how to set it properly, so that it allows e.g. only numbers.
    Please help me to solve this issue.
    Thank you

  • How can i animate .jpg image?

    hi
    how can i animate images which i edit in GIMP?
    i mean, i have 1 video clip showing a tree. and then i have 1 .jpg image of an airplane
    how can i make that airplane from jpg image to appear in the video showing the tree? i want to make that airplane crash into the tree and explode.
    i see a lot of similar stuff on youtube (like "cyriak animation mix")  but i don't know what this technique is called. animation of still images? google search gave me lots of dubious results, none of them came straight to the point.
    all i know it involves some manipulation of keyframes but i need to know more keywords to further research this technique. or better yet - find a decent article explaining basics.
    can somebody help?

    First, you will probably want to Key out the background around the plane. Look into Chorma Key, or one of the other Keying Effects in PrE, depending on how the plane was shot, or created. If you created it, you can probably Mask out any background, and Save_As a format, that support Transparency, such as with an Alpha Channel Mask.
    Then, with the plane on a higher Video Track, than your tree, use the Fixed Effect>Motion>Position to Keyframe the Position of the plane, moving it across the Frame. Steve Grisetti has a great Learning Series on Basic Keyframing and Advanced Keyframing, available at Muvipix.com: http://www.muvipix.com/products.php?searchphrase=Basic+Keyframing&btn.x=-1091&btn.y=-78
    Good luck,
    Hunt

  • How to insert a JPG image in a column of type "image" in sql server 7.0 ??

    hi all,
    I have a table with 2 columns.
    First col is of "Name" and second col is of type "image" .
    I am using sql server 7.0 on window 2000.
    now i have created table. I want to insert a jpg/gif image in its 2nd column.
    How can i do so ? and how i can i read the image object after insertion ?
    I am using 2nd col of type "image" and NOT Binary or varBinary.
    Any idea will be highly appreciated.
    Thanks in advance.
    AlwaysJava

    hi all,
    I have a table with 2 columns.
    First col is of "Name" and second col is of type
    "image" .
    I am using sql server 7.0 on window 2000.
    now i have created table. I want to insert a jpg/gif
    image in its 2nd column.
    How can i do so ? and how i can i read the image
    object after insertion ?
    I am using 2nd col of type "image" and NOT Binary or
    varBinary.
    Any idea will be highly appreciated.
    Thanks in advance.
    AlwaysJavaHi,
    Below are some excerpts from my program.. which was doing image insertions and retrievals also.. I have included the image insertion and retrieval portion.. retrieval can be done in more than one ways.. one of them is given.. for very large images, u can read chunks of data from the input stream and write it to the disk. for smaller ones , the given methods work very well..
    I tested the program with jdk1.4.0 and aveConnect3.0 driver. on an
    SQL server 7 machine from my box running windows 2000... and it worked..
    Im not still sure if this is the optimised way.. there can be other more optimised methods..
    hope this clears your problem..
    cheers,
    -Jer
        Connection conn = null;
        Statement stmt = null;
        ResultSet rst = null;
        PreparedStatement pstmt = null;
        FileInputStream fis = null;
        FileOutputStream fop = null;
        File file = null;
        InputStream is = null;
        String createtable = "Create table testtable (name varchar(32),_image image)";
        String inserttable = "Insert into testtable values (?,?)";
        String retrievetable = "Select _image from testtable";
        String droptable = "Drop table testtable";
        String url = "jdbc:AvenirDriver://CodeServer:1433/test";
        conn = DriverManager.getConnection(url,"test","test");
    //Create the table
        stmt = conn.createStatement();
        stmt.execute(createtable);
    //Insert the file into the table
        file = new File("input.gif");
        fis = new FileInputStream(file);
        pstmt = conn.prepareStatement(inserttable);
        pstmt.setString(1,file.getName());
    //Set the filestream to the binary stream into the image in the table
        pstmt.setBinaryStream(2,fis,fis.available());
    //Updating the table
        pstmt.executeUpdate();
    //clean up the streams and atatement
        fis.close();
        pstmt.close();
    // Retrieve the image from the table..
        pstmt =  conn.prepareStatement(retrievetable,ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);
    // execute the Query
        rst = pstmt.executeQuery();
    //jump to the first row of the resultset
        rst.beforeFirst();
        rst.next();
    //get the inputstream from the image object in the  result set
        is = rst.getBinaryStream(1);
    //Writing the data in the inputstream into an outputfile
              //Using getbytes method from the result set
                   byte[] bytearray = rst.getBytes(1);
                   baos = new ByteArrayOutputStream();
                  baos.write(bytearray);
                  fop = new FileOutputStream ("output.gif");
                  baos.writeTo(fop);
    //using the input stream and storing the data in bytearray
    //allocating the buffer size to store the data from inpuit stream ... here whole inptstream is allocated..
    //(The buffer size can be varied if the file is too large and the reading be..
    //  ..done in loop , to read small chunks from the input stream and write it to the file)
        byte[] bytearray = new byte[is.available()];
    //to write the data in the byte array into an output file
        baos = new ByteArrayOutputStream();
        baos.write(bytearray);
        fop = new FileOutputStream ("output.gif");
        baos.writeTo(fop);

  • How to set folder icon image in OS X Lion?

    I set my folder's icon image in OS X Leopard before, but I don't know how to do that in Lion.  In Leopard you simply copy the icon image from an Info window of a file, and paste that into the folder's icon image in the top left corner of its Info window.  In Lion I don't see the icon of the file in its Info window as a preview, but rather I see only a generic JPG file icon.  Any ideas?

    Can you explain why there was no thumbnail for that file?
    The OS does not create or add thumbnails, previews, nor custom icons to images or other files. Although it displays files with what appears to be a custom icon, it is not part of the file itself; it is created on the fly, just for display. Since it is not part of the file, it does not appear in the Get Info window.
    Back in OS 9 days when you downloaded an image file from the web, either via drag and drop or via the download mechanism, the image file would typically be placed on the drive as a QuickTime image with both a custom icon and a preview image added to it.
    I skipped earlier versions of OS X, and started with Snow Leopard, so don't know about earlier versions of OS X. Apparently the auto creation and addition of a custom icon and preview have been dropped in later versions in favor of using Preview to generate a temporary (for display only) custom icon on the fly. One result of this is that image file sizes are kept reasonably small - adding a suite of custom icons and a preview image to the file itself increases the file size a lot; it's not unusual for those additions to double the file size, or more.

  • How to set a background image in javafx?

    Hi everyone,
    I draw FXML GUI,it includes labels and ProgressBar,load it in JavaFX, this is a snippet.
    root = FXMLLoader.load(getClass().getResource("StartMenuFXML.fxml"));
    label1=(Label)root.lookup("#label");
    label2=(Label)root.lookup("#label");
    progressBar = (ProgressBar)root.lookup("#ProgressBar");
    scene=new Scene(root,600,400);
    stage.setTitle("Start Progress");
    Progress p = new Progress();
    p.start();
    stage.setScene(scene);
    stage.show();
    I need to add a background picture in it, so I add the statements:
    GridPane pane = new GridPane();
    pane.setTitle("-fx-background-image: url('image1.jpg')");
    and change: scene =new Scene(pane,600,400);
    It can display the background picture, but I don't know how to display the labels and ProgressBar on the background picture.
    Give me a good resolution please!
    Thank you so much!

    James_D,
    Your answer is the exact solution, you are a real expert.
    Thank you very very much!!!

  • How to set crystal report image object's file path dynamically from file system in vb 2010

    I using visual studio 2010 and sap crystal report is installed on it.
    I have a report with picture box on it and i need to load image to this picture box from vb e.i.
    Dim imgPhoto As CrystalDecisions.CrystalReports.Engine.PictureObject = crShortReport.ReportDefinition.Sections(3).ReportObjects("imgPhoto")
    imgphoto.image= loadpicture("c:\abc.jpg")
    So, please help...
    Thanks

    Crystal reports is a thrid party program
    and is
    not supported by
    Microsoft, you will have a beter chance getting help here
    http://scn.sap.com/community/crystal-reports.

  • How do I view jpg images on iPhone 4?

    My daughter sent me some pictures via text message from her windows 7 phone. I can see them in the text message but when I saved them to my iPhone 4, I can't see them. The only thing that shows up in the photo album is a gray box with the letter 'jpg' in it. Do I need an app to view? Are the files too big? Assistance please. :-)

    If its not installed, there's nothing to delete.
    Perhaps the OP is referring to hiding the purchased apps when viewing their history in the app store.  For that, one can use a computer to go to the "Purchased" section of the iTunes store, then while viewing the list of purchased items you'll see a small "x" in the top corner of the item you hover over, click on that and the item will be hidden from your purchase history from any device used to browse your past purchases.

  • How to set borderstyle in image

    hi
    i have 10 layout in 10 images.
    if mouse over on the layout that specific layout should change the border style.
    Is it possible in flex 4.
    anybody suggest me
    regards
    athi

    This forum post will likely lead to an answer:
    http://forums.adobe.com/thread/443718
    If this post answers your question or helps, please mark it as such.

Maybe you are looking for

  • Calling a HTTPS Web Service through a proxy

    Hi All, I am trying to make a web service proxy for a service runnig on the weblogic server over https connection. While I am configuring the proxy I am getting an error saying that Unable to tunnel through proxy. Proxy returns "HTTP/1.1 403 Tunnel o

  • WRT120N - error 323, asking for username & password

    hi, I just got a brand new linksys wrt120n router for my new computer. but no matter how I try to connect wireless to the internet, I get an "error 323", where it asks for a usename and a password??? I have no such codes! what can i do?? greetings fr

  • Icons in Hierarchy structure

    Hi all I have a function module for getting  Organizations from the database and display them in the form of a tree. The problem is that, in the organization hierarchy the icon for the child id( when no org underneath) should be different from the ic

  • DB Session-Problem

    Hi We have a problem with the DB-Session-Handling. We have a Communication Channel,  that reads data from the database. We open and close this channel from extern via a scheduling-tool. Each time when the channel starts and stops 5 minutes later, it

  • How to add password to catalog?

    I wont to add my girlfriend photos to my n73 but i don't wonna that my parents or brother to see it.So i wondering is there any way to add password to catalog.Is there any soft that i cna download or buy?