Question about displaying image with JLabel

Hi
I need to display an image. The image is determined by the user at run time, so the dimension of the image is unknown. Is it possible for JLabel to stretch the image so the whole image(instead of only part of it) will always fits into a certain dimension?
thanks.

For this you need to create a custom class that extends ImageIcon
and define the methods there.
see Java Tutorial for it.
For eg., to scale an image , you can use
JLabel label = new JLabel();
Image img = new ImageIcon("Pics/Ash.jpg").getImage();
int width = img.getWidth(null);
int height = img.getHeight(null);
//This would scale the Image by 200%
Image bimg = image.getScaledInstance(width*2, height*2, Image.SCALE_SMOOTH);
label.setIcon(new ImageIcon(bimg));
//There is also another way
//Use drawImage and use BufferedImage
BufferedImage buff = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
Graphics g = buff.getGraphics();
//Scale the Image to 200%
g.drawImage(img, 0, 0, width*2, height*2,  null);
lable.setIcon(new  ImageIcon(buff));Hope you get the idea!!

Similar Messages

  • Question about displaying data

    Based on the search criteria I need to show some info. with check box on each item, but it might retrun upto fifty items (between 1 to 50 items). Should I create checkbox/output text dynamically or how do I handle this scenario? In the jspx how do I loop it and display? Thank you.

    hi user13094256
    See my reply in your other forum thread with the same question
    at Question about displaying data
    regards
    Jan Vervecken

  • How can i Display images with may own table

    Hi
    I want display images with my own table. How can I use in this query.
    SELECT    '<a href="#" onclick="javascript:'
           || 'getImageHeight(''my_img'
           || '#ROWNUM#'');javascript:redirect'
           || '(''f?p=&APP_ID.:212'
           || ':&SESSION.:DISPLAY:NO::P212_IMAGE_ID:'
           || ID
           || ''');">'
           || '<img src="#IMAGE_PREFIX#edit.gif" '
           || 'alt="Edit"></a>' ID,
              '<img id="my_img'
           || '#ROWNUM#" src="#WORKSPACE_IMAGES#'
           || filename
           || '"/>' image
      FROM wwv_flow_filesThanks
    Nr
    Edited by: user10966033 on Sep 28, 2009 1:41 PM

    You don't use #workspace_images# since that is for STATIC files, not images in a table..
    see this thread for help: Re: Display image from blob
    Thank you,
    Tony Miller
    Webster, TX

  • Mail will not display images with .jpeg extension. .jpg works fine. (displays in place when opening the email. What plug-in would correct this?

    Mail will not display images with .jpeg extension. .jpg works fine. (displays in place when opening the email. What plug-in would correct this?

    If you think you're insane now, try maintaining those pop up menus.
    As far as I know, these menus have not been updated since FW 8, so 
    they are at least two versions old.
    Save yourself a lot of grief by avoiding those menus. There are many 
    other products on the market which do a much better job of creating 
    and maintaining this type of navigation structure.
    Read this link before you climb any higher on this slippery slope:
    http://apptools.com/rants/jsmenu.php
    There was another blog post by the fellow who originally wrote the pop 
    up menu feature, but I can't seem to locate it. Even he says stay away 
    from them.
    Not the answer you probably want, but I hope it helps, nonetheless.
    Jim Babbage

  • A few questions about using PS3 with 27" iMac display...

    Hey people, I had a few questions about how I could possibly get my ps3 connected to the iMac's 27" screen. First of all, could you guys list some adapters that would be able to convert the HDMI to Mini displayport? That would be great. The only one I know of is that Dr. Bott Digital Video link.
    Okay secondly, I was wondering if I do get the the ps3 connected with the iMac's display with an adapter to convert HDMI to mini DisplayPort, would it be in HD? Would I be able to play ps3 games or watch blu-ray movies in 1080p HD format?
    Thanks!

    Welcome to the Apple Discussions!
    This has been asked a number of times here since the intro of the 27" iMac. The answer is very expensive US$149 or more converters and sometimes even more expensive to maintain the resolutions that you seek.
    http://lowendmac.com/ed/bashur/09db/dvi-to-mini-displayport.html
    Dah•veed

  • Questions about PDF exporting with InDe CS5.5

    Hey all,
    A couple questions about exporting to PDF from the latest version of InDe.
    First, I have noticed that it seems to take a lot longer to get to a PDF. Any suggestions for how to speed up the process? It took 8 minutes or so to generate a low-res PDF (for print) of a 24pp document with a few placed images and vector graphics. Wow, that's a long time to wait, especially for a proof.
    Second, the background task... if I get it going on making that 8-minute PDF and then work some more on the document, what exactly is in the PDF? Usually I save before making a PDF or printing. So, is the last version saved what will be in the PDF?
    (As an aside, this ability to work on the doc while generating a PDF seems kind of weird. Generally one makes a PDF for proofing, or even for printing, when all the changes have been made and everything is "final". So, I see no benefit to being able to work on my document while it's making a PDF, as I'm probably finished making revisions for the time being. I have to say that I kind of like the progress bar you get when you make an interactive PDF, as you know you can't work on the document when that's on the screen... )
    Thanks as always.

    First, I have noticed that it seems to take a lot longer to get to a PDF. Any suggestions for how to speed up the process? It took 8 minutes or so to generate a low-res PDF (for print) of a 24pp document with a few placed images and vector graphics. Wow, that's a long time to wait, especially for a proof.
    Yes, this is abnormally long (and too long), something is wrong. What's the full version of InDesign you are running, as reported by holding down Cmd or Control and selecting About InDesign?
    Second, the background task... if I get it going on making that 8-minute PDF and then work some more on the document, what exactly is in the PDF? Usually I save before making a PDF or printing. So, is the last version saved what will be in the PDF?
    Saving is not related. InDesign makes a database snapshot of your document the moment you begin the PDF export, and makes the export relative to that snapshot, regardless of edits you continue to make during the export process, and regardless of saving. Of course saving first is a good idea, for several reasons, not the least of which it sounds like something's fairly seriously wrong with your document or your InDesign installation.
    We recommend you trash your preferences and export your document to IDML and see if either of those things changes this 8-minute behavior...err, assuming you're running 7.5.2.318.
    (As an aside, this ability to work on the doc while generating a PDF seems kind of weird. Generally one makes a PDF for proofing, or even for printing, when all the changes have been made and everything is "final". So, I see no benefit to being able to work on my document while it's making a PDF, as I'm probably finished making revisions for the time being. I have to say that I kind of like the progress bar you get when you make an interactive PDF, as you know you can't work on the document when that's on the screen... )
    Yeah, I think the primary benefit is if you are likely to work on 2 or more files in parallel, so you can finish A and export A and then switch to B. If you'd like a dialog box to pop up when export is done, check out my exportPop script from this post: ANN: automatic dialog after background export (exportPop.jsx.

  • Questions about supporting TLF with Halo components in Flex 4.1

    We recently decided to upgrade to the Flex 4.1 SDK after a year or so at 3.2.  We have been asked to not use the new SPARK components yet because our products would then have a mistmatch of Halo and Spark components in the UI.  We have built support for our Halo components to display html through the ".htmlText" property for the Text components.  For example, we can display strings such as "<p>Choose <b>one</b> option:</p>".  With the upgrade to Flex 4.1 a couple of questions about supporting bi-directional text have come up.  My understanding is that in order to support bi-directional text we need to use the Text Layout Framework.  Does anyone have a suggestion on how we can utilize the TLF with the Halo components in Flex 4.1?    Can we still use the ".htmlText" property somehow or is there a new property that understands the TextFormat markup?  We would love to still be able to use the limited html tags that are supported for the "htmlText" property.  Is there an option where that syntax is still understood?
    Thanks in advance!
    David

    The halo components use TextField, and the spark components use TLF. Both sets have support for some html markup to import and export text. To use bidi text, you have to use TLF; TextField won't work properly.
    It is possible to use TLF to build your own components, and this can work well particularly for applications with specialized needs. But if you need bidi support for advanced components like DataGrid and List, then you should use the spark components.
    Thanks!
    - robin

  • PE9 get confused about displaying images

    Been using PE9 for a few weeks and within the past couple of days it seems to get confused about which image should be displayed within the timeline. Have a medium size project with 30-40 jpg's in it and when shown in the timeline (or in the monitor window), PE9 replaces the image associated with a particular file with an image from another file. In the Project list you can get Properties and the path\file name shows up perfectly but PE9 uses the image from another file. Tried closing the project, and PE9 - no help. Tried re-booting Windows 7 (64 bit) - nop help. This seems to get worse as time goes on and I have not been able to find a solution.
    Bob

    My photo's are either 720 x 480 or 720 x 1080 depending on whether they are landscape or portrait.

  • Problem in displaying images using JLabel in Netbeans

    hi all,
    i am trying to display an image on JLabel in Netbeans.The image is visible in the design view but not displayed in the runtime.Can anyone help me out with suggestions???

    Duplicate - answer here http://forum.java.sun.com/thread.jspa?threadID=5153605&messageID=9578626#9578626

  • Noob question about HDR images

    hi everybody! i am reading this book about photoshop hoping to understand a lot more than i already know about pixels and colors and image dinamics and such..i got to the chapter about HDR images and here's what i dont get. as i understand, given a HDR image it has 32 bit depth meaning its file contains much more information about contrast and brightness than any existing monitor can output, so when u open it in photoshop u will never see its true quality. my question is( and i admit it may seem pointless to some, but i am committed to understand the cause and purpose), when converting it to 8 or 16 bit depth this window pops up asking me to tweak gamma, exposure, shadows and highlights, etc., but why is this linked to the conversion process? why not simply convert it, maintain the same appearance as before and then if needed manually adjust using all the image controls from the photoshop menus? i have CS6, if that matters.

    I don't know if this will help, but I've heard about HDR monitors (still very expensive), which supposedly very accurately display the HDR values. If you hang one on the wall in your house, people might think it's a window, since it is literally a source of light, in the same way a window to the outside world is.
    Possibly the most surprising use of HDR imagery is in 3D apps where global illumination models are used. HDR imagery literally is the only source of light for these images. There are no lights in the scene, only HDR imagery. This is because of the great dynamic range of HDR.
    A more practical (to me) use of HDR is when resurrecting antique images. If you scan multiple exposures from old prints, then create HDR, sculpting values in 16-bit becomes a very powerful tool, only due to the HDR value range.
    Photoshop, although it can edit very well in 16-bit, can only show 8-bit representations of HDR imagery, since almost all monitors are 8-bits per channel. Because of the monitors, we can only see a small part of what is actually present in the HDR file.
    I've never done it, but I imagine that if we all had HDR monitors, we'd need to wear protective glasses (like you wear driving in your car when the sun is out) most of the time to do our work.  :+)

  • A question about a method with generic bounded type parameter

    Hello everybody,
    Sorry, if I ask a question which seems basic, but
    I'm new to generic types. My problem is about a method
    with a bounded type parameter. Consider the following
    situation:
    abstract class A{     }
    class B extends A{     }
    abstract class C
         public abstract <T extends A>  T  someMethod();
    public class Test extends C
         public <T extends A>  T  someMethod()
              return new B();
    }What I want to do inside the method someMethod in the class Test, is to
    return an instance of the class B.
    Normally, I'm supposed to be able to do that, because an instance of
    B is also an instance of A (because B extends A).
    However I cannot compile this program, and here is the error message:
    Test.java:16: incompatible types
    found   : B
    required: T
                    return new B();
                           ^
    1 errorany idea?
    many thanks,

    Hello again,
    First of all, thank you very much for all the answers. After I posted the comment, I worked on the program
    and I understood that in fact, as spoon_ says the only returned value can be null.
    I'm agree that I asked you a very strange (and a bit stupid) question. Actually, during recent months,
    I have been working with cryptography API Core in Java. I understood that there are classes and
    interfaces for defining keys and key factories specification, such as KeySpec (interface) and
    KeyFactorySpi (abstract class). I wanted to have some experience with these classes in order to
    understand them better. So I created a class implementing the interface KeySpec, following by a
    corresponding Key subclass (with some XOR algorithm that I defined myself) and everything was
    compiled (JDK 1.6) and worked perfectly. Except that, when I wanted to implement a factory spi
    for my classes, I saw for the first time this strange method header:
    protected abstract <T extends KeySpec> T engineGetKeySpec
    (Key key, Class<T> keySpec) throws InvalidKeySpecExceptionThat's why yesterday, I gave you a similar example with the classes A, B, ...
    in order to not to open a complicated security discussion but just to explain the ambiguous
    part for me, that is, the use of T generic parameter.
    The abstract class KeyFactorySpi was defined by Sun Microsystem, in order to give to security
    providers, the possibility to implement cryptography services and algorithms according to a given
    RFC (or whatever technical document). The methods in this class are invoked inside the
    KeyFactory class (If you have installed the JDK sources provided by Sun, You can
    verify this, by looking the source code of the KeyFactory class.) So here the T parameter is a
    key specification, that is, a class that implements the interface KeySpec and this class is often
    defined by the provider and not Sun.
    stefan.schulz wrote:
    >
    If you define the method to return some bound T that extends A, you cannot
    return a B, because T would be declared externally at invocation time.
    The definition of T as is does not make sense at all.>
    He is absolutely right about that, but the problem is, as I said, here we are
    talking about the implementation and not the invocation. The implementation is done
    by the provider whereas the invocation is done by Sun in the class KeyFactory.
    So there are completely separated.
    Therefore I wonder, how a provider can finally impelment this method??
    Besides, dannyyates wrote
    >
    Find whoever wrote the signature and shoot them. Then rewrite their code.
    Actually, before you shoot them, ask them what they were trying to achieve that
    is different from my first suggestion!
    >
    As I said, I didn't choose this method header and I'm completely agree
    with your suggestion, the following method header will do the job very well
    protected abstract KeySpec engineGetKeySpec (Key key, KeySpec key_spec)
    throws InvalidKeySpecException and personally I don't see any interest in using a generic bounded parameter T
    in this method header definition.
    Once agin, thanks a lot for the answers.

  • Question about Logon ticket with user mapping at BI-JAVA environment

    We're implementing BI 7.0 including BI Java and SAP EP for end user
    access.
    I have two question about SSO method when we're using BI Java.
    I know we can simply configure SSO logon ticket with BI-Java(EP
    included) and BI-ABAP through BI template installer and we already
    succeeded in that case.
    But the problem is we want to change it to user mapping SSO method for
    some our internal reason.
    After we configure user mapping SSO, we've got SSO failed error when we
    call BI-Java stuff like BEx Web Application iView.
    After many testing implemented, we found SSO Logon ticket with user
    mapping (using SAP reference system). It seems working now.
    But our question is "Is it no problem when we use SSO logon ticket with
    user mapping?" Is there any restriction or issue?
    One more question is we can ONLY use user base mapping when reference
    system used. How can we assign BI-ABAP users to EP Group?

    Using an SAP Reference system is allright. But if the reason u r going for this is because of different usernames in EP and BI, why dont you go for user mapping.
    Anyways, on restriction of reference syetms is that you can have ONLY ONE reference system defined in portal. In you case you can only have the BI system defined.
    Hope this helps!!

  • Displaying images with a menu ring

    Hi,
    What i want is  a menu ring ring that can give a choice to run indivdual tests . Test A, test b , test c test d . The results of each test to be displayed seperately with text on each image showing from which test the image came from,
    Iam attaching an file that iam trying to implement this on.
    Thanks for your help.
    (requirements labview 7.1 and vision assistant)
    Attachments:
    help.vi ‏128 KB

    I think you can use the Picture Ring for your appliction.
    - Partha
    LabVIEW - Wires that catch bugs!

  • Displaying Image using JLabel in swings

    I am not understanding how to display a image in swing using JLabel Component.
    I am writing in the following manner:
    // importing necessary packages
    in init() method
    public void init()
    Container cp= getContentPane()
    JLabel jl=new JLabel("Image",new ImageIcon("<image>.gif"),JLabel.CENTER);
    cp.add(jl);
    applet is running and only label msg is displaying but not the image.
    Please help me so that i can solve this problem.where the image is to be placed??and how it has to be included?
    Please provide me the solution.

    cp.add(new JLabel("Image",new ImageIcon(new java.net.URL (getCodeBase(),"Test.gif")),JLabel.CENTER));

  • Question about brightening images and automating layers

    I've been using Photoshop CS5 for a while now but there are still a few things I'm wondering about.
    The first is about brightening an image without adding or reducing too much contrast at the same time.  If I increase the Brightness slider in the Brightness/Contrast window it often adds too much unwanted contrast and will wash out parts of the image or cause too much saturation.  Same thing when using Curves to brighten the image.  On the other hand I've found that using Levels to brighten the image reduces too much contrast and desaturates the image too much...and then when I add more contrast in afterward, parts of the image will become washed out again.  So far the best solution I've found has been to brighten the images with Shadows/Highlights, but this will often pose its own set of problems by creating or eliminating shadows in a way that doesn't flatter the image.  It can also add too much contrast in some cases.  Is there any other way around this that I'm missing?  Or is this all to be expected when brightening images?  The only other workaround I've found has been to add in separate un-affected layers for the areas of the picture that become too washed out when the brightness is increased but then there's always a problem of getting those parts of the picture to match up with the rest afterward.
    The second is about having layers for each change applied to an image.  Is there any way to have each change that is applied to an image automatically also be made into its own separate layer?  For example, if I sharpen a part of the image that would automatically become layer 2, then if I adjusted the saturation that would automatically become layer 3 and so on.  I know the History Panel does something very similar to this, and that's the type of thing I'm looking for, but I'd like each of those changes being made into a layer instead of just a recorded history state.  This way, for example, I could individually adjust each change with the opacity slider and compare the image with and without some of the changes by clicking the eye icon next to each layer.  I know new layers can be created manually but I'm looking for some way to automate it.
    Thanks for the help.

    The second is about having layers for each change applied to an image.  Is there any way to have each change that is applied to an image automatically also be made into its own separate layer?  For example, if I sharpen a part of the image that would automatically become layer 2, then if I adjusted the saturation that would automatically become layer 3 and so on.  I know the History Panel does something very similar to this, and that's the type of thing I'm looking for, but I'd like each of those changes being made into a layer instead of just a recorded history state.  This way, for example, I could individually adjust each change with the opacity slider and compare the image with and without some of the changes by clicking the eye icon next to each layer.  I know new layers can be created manually but I'm looking for some way to automate it.
    You seem to have no firm grasp yet on the concept of non-destructive image editing using Photoshop’s existing options, specifically Adjustment Layers, Smart Objects/Smart Filters and Layer Masks.
    The Layers structure is a much more valuable tool than the History in my opinion.
    Instead of applying an Adjustment or Filter destructively you might want to try applying it as an Adjustment Layer or a Smart Filter (either with its own Mask or on a copy of the Smart Object with a Layer Mask, because all Smart Filters applied to one instance of a Smart Object must share one Mask).
    Those Layers can subsequently be changed with regard to Opacity, Blend Mode etc. or the Adjustment and Filter settings themselves.

Maybe you are looking for