Can I render a JPanel to a BufferedImage?

I'm doing some unusual things with laying out components, and would like to be able to render the content of a JPanel directly to a BufferedImage.
I woudl like to
- create a BufferedImage to use as a back buffer
- define a Dimension for my JPanel component and cause it to layout itself to this dimension
- create a graphics on my BufferedImage
- apply an arbitrary AffineTransform to my Graphics2D
- render my JPanel with the Graphics2D
Is there a way to do this? I've been scratching my brain, but can't thin o fhow to render outside of AWT..
Mark McKay
http://www.kitfox.com

No need to subclass anything:
JSplitPane sp = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,
            new JTree(), new JScrollPane(new JTable(20, 5)));
JPanel p = new JPanel(new GridLayout(1,1));
p.add(sp);
p.setBorder(BorderFactory.createTitledBorder("This is a test:"));
JFrame f = new JFrame("App");
f.getContentPane().add(p);
f.pack();
BufferedImage image = new BufferedImage(p.getWidth(), p.getHeight(), BufferedImage.TYPE_INT_RGB);
Graphics2D g = image.createGraphics();
p.paint(g);
g.dispose();
ImageIO.write(image, "jpeg", new File("test.jpeg"));

Similar Messages

  • How can I render an active link (yrl) within a UIX/XML page

    How can I render an active link (url) within a UIX/XML page.
    How can I get <jbo:ShowValue> to work in UIX/XML, or is there another way?
    Bill G...

    It may seem strange, but the <contents> of <rawText> aren't actually
    raw - it's only the "text" attribute that's raw. (It seems strange because
    it is. Ah well.) This is different from UIX JSP.
    So, try something like the following:
    <bc4j:attrScope name="Notes">
    <contents>
    <rawText text="&lt;a href=&quot;"/>
    <rawText>
    <boundAttribute name="text">
    <bc4j:attrProperty name="value"/>
    </boundAttribute>
    </rawText text="&quot;&gt;"/>
    Some text in the link.
    <rawText text="&lt;/a&gt;"/>
    </contents>
    <bc4j:attrScope>
    Thankfully, this will be much simpler in 9.0.3, when the following
    will work:
    <link text="Whatever you want">
    <boundAttribute name="destination">
    <bc4j:attrValue name="Notes"/>
    </boundAttribute>
    </link>

  • Can Lightroom render 1:1 Previews when importing my Photos?

    Q: Can Lightroom render 1:1 Previews when importing my Photos?
    FAQ revised 25 April 2009
    Ans: Prior to version 1.3 Lightroom did not support 1:1 preview rendering during import, the actual options for  Initial Previews being:  Embedded or  Standard. However, more recent versions allow four types of previews to be rendered during import (i.e.  Minimal, Embedded & Sidecar, Standard,and  1:1). It's also worth noting the following on Lightroom import behaviour: 
    1.  Minimal (Lightroom default) or Embedded & Sidecar is by far the quickest method for getting your photos into the Lightroom catalog. However, the lack of Standard, which is the minimum that Lightroom can actually work with, means that the application will render standard-sized on demand (i.e. as thumbs/photos become visible within the photo Content area). Asking Lightroom to undertake this task at the same time as you're trying to use the application will result in sub optimal performance. 
    2. Importing your photos with the  Standard preview selected within the Import dialog will take longer than 1 above, but on completion Lightroom will already have previews that match the minimum requirement for working in the Library. Assuming that you won't be looking at every image at 100% (i.e 1:1) then this preview size will allow you to quickly review, rate, label, even make quick colour/tone adjustments, etc the photos within the Library module. If you need to see a photo at 100% then Lightroom will render that preview on demand (while it's being rendered you'll see the "Rendering Preview" overlay appear at bottom of preview).  Note that when using a 23" or larger monitor it to is best to set the Standard sized previews so that they are rendered at 2048 pixels
    3. Importing your photos with the  1:1 preview size selected will result in Lightroom taking even longer to complete the import process than would have been the case if standard-sized had been chosen. 1:1 previews also take up significantly more disk space than standard-sized.
    If you're not going to be working on the photos immediately after import but do need to get them into Lightroom as quickly as possible, then the best option would be to choose import option 1. Once the photos have been imported choose either  Render Standard-sized Previews or  Render 1:1 previews from Library module Library>Previews menu.

    When I search these forums for "CFCopyFormattingDescription", I find a bunch of crash reports posted that look almost exactly the same as mine.  It appears there's a bug in iPhoto, perhaps when reading metadata from the JPG file (readRawTiffPropsFromPath).
    Interestingly, the Preview app can open and display the file just fine.  I even opened the inspector and it showed all of the TIFF and exif metadata just fine, no crash.  The file also opens just fine on Windows.
    Now how do we get the attention of the iPhoto development team so I can send them the photos, have them reproduce the crash, and fix it?

  • Adobe Media Encoder can´t render out AE Ray-Trace Composition

    Hey,
    AME can´t render out my composition (or sequence if i include the comp in a PP sequence) which includes some 3D stuff.
    I am able to render it out in AE in a few minutes, preview it easily in AE and even in PP but i´m not able to render it out in AME or PP.
    AME says it would take like 10+ Hours to render it and doesn´t come to an end.
    I tried multiple encoding settings but nothing worked.
    Also i checked, that cuda rendering is enabled in all my Adobe programs, but nothing helped...
    AE File .aep :
    Dropbox - Twitch Infovideo.aep
    AME .epr Preset for encoding :
    Dropbox - Media Encoder Error Test.epr
    Thanks for helping,
    Johannes

    It raises another question: what settings do I need to encode the comp in 720p resolution without taking up lots of space?
    Well, it depends on whether you need a production master (something for broadcast, for example, or to use as a source for other encoding tasks) or if you want a version for distribution. If it's the former, there's nothing wrong with "lots of space" - A Quicktime file with PNG or Animation codec is a good idea, but it will take a lot of space. If it's the latter, H264 is perfect but there's no built-in preset to take 720 material to the web.
    You could do this:
    * Pick the generic H264 template. You'll see that it will give an error if you attempt to render, because the default setting uses an H264 profile/level which doesn't let you use HD resolutions.
    * In the H264 video options, set the "Profile" menu to "Main" and "Level" to 4.0. That will keep it compatible to Quicktime and Flash player, while allowing larger frame sizes and higher bit rates.
    * Set Target Bitrate to 5-8 Mbps and Maximum Bitrate to 9-10 Mbps if you're targetting web delivery. That's a bit over what Apple uses for 720p content on the Apple TV, for example.
    The H264 original preset will instruct you in the comment field to stretch to 640x480 in Output Module. There's no need, since you are using a profile/level combination which allows higher frame sizes.

  • How can i render a dynamic html file in jsp page

    Hi everybody,
    i am trying to render a dynamic html file in jsp page with the result of querying a database.
    The response of the query is a xml document. And i have a stylesheet to transfer it to html.
    How can i render the html in a jsp file?

    I am using below code for HTML files
    private var appFile:String="index.html";
    if (StageWebView.isSupported)
                        currentState = "normal";
                        webView.stage = stage;
                        webView.viewPort = new Rectangle( 10, 130, (stage.stageWidth)-20, 750 );
                        var fPath:String = new File(new File("app:/assets/html/aboutus/"+ appFile).nativePath).url; 
                        webView.loadURL(fPath);
                        addEventListener(ViewNavigatorEvent.REMOVING,onRemove);
                    else {
                        currentState = "unsupported";
                        lblSupport.text = "StageWebView feature not supported";
    above code is working fine for me.

  • How can i render one facet in panel splitter based on conditions?

    Jdeveloper Version - 11.1.1.5
    How can i render one facet in panel splitter based on conditions?
    Ex : In horizontal Panel splitter first facet - af table
    second facet - af table
    if any one table estimated row count is zero i nedd to render the respective facet?
    is it possible?
    Please help..
    Thanks
    sk

    Yes you can do it but not on facet you can apply rendered attribute to the any of the child component of the facet.
    Thanks
    Raghav

  • Hi, I can't figure out why I can't render on my timeline. I highlight the segment hit "Apple-R" and it gives me a weird message about "conforming HDV video...." and the bar goes as far as 60-66% and holds there forever. It never renders even partially.

    Hi, I can't figure out why I can't render on my timeline. I highlight the segment hit "Apple-R" and it gives me a weird message about "conforming HDV video...." and the bar goes as far as 60-66% and holds there forever. It never renders even partially.

    Yes, I know. I have been working with HDV for some time. I am wondering why it doesn't render when it needs to.. the red and bright-green lines are above, and I've set the render settings such that ANYTHING I highlight and hit apple-R will render. But its not rendering at all.

  • Can't render Themes in iMovier 6.0.3

    I'm having problems with rendering Themes in iMovie 6.0.3.
    I can create the Theme fine. But after I hit "Apply", the theme clip sits in the Clip viewer - complete with its little red "I'm rendering" line - for hours (and hours), apparently doing nothing.
    I can't save the project without iMovie telling me there are still effects rendering, and that I need to discard the rendering to save the file. I can't render the Theme (because it appears to be in some kind of loop). I can't therefore edit m,y movier in the way I want - and my little daughter wanrts a DVD of her school play
    After reading this forum, I removed Flip4Mac and also every other codec I could find on my iMac (I didn't have 3ivx but did have other DivX codecs). I've run plutil to try and find corrupted preference files. I've tried restarting. I've tried creating the Themes in different ways.
    In short, everything I can think of, and the fecker still won't work!
    Anyone got any bright ideas? iMovie is a flagship (and workhorse) Mac app surely - how on earth can it be barfing at doing something so straightforward?

    Stuart, we've seen a number of reports here recently of problems with Ken Burns and Themes rendering after Migration Assistant is used on a new Mac to move files from an old Mac to a new one. Did you do that?
    The problem affects all user accounts. The cause of the problem is still unknown.
    http://discussions.apple.com/click.jspa?searchID=-1&messageID=4091548
    http://discussions.apple.com/click.jspa?searchID=-1&messageID=4043811
    The first thing to do, however, is to be absolutely certain you've removed all third-party QuickTime add-ons and iMovie plug-ins. They can be in one of several folders:
    http://discussions.apple.com/message.jspa?messageID=4030731#4030731
    Karl

  • Can't render effects in FCP7 for ALL-INTRA video shot on GH3

    I can't render effects on FCP 7 for footage shot on a Panasonic GH3 camera.
    Original files are shot in ALL-INTRA mov files 1920x1080, 25p format. Original files are H-264, and are imported without conversion, edited on  Easy Setup HD XDCAM HD 1080p25.
    I can render effects on the timeline, but there is massive breakup when I export the edit.
    Exporting raw files, without special effects is OK.
    Any suggestions?

    That camera shoots AVCHD...not AVCIntra. Only P2 cameras shoot AVCIntra.
    "Original files are H-264, and are imported without conversion"
    That's your problem.  FCP doens't work with H.264 well.  YOu need to convert the footage to ProRes, and use a ProRes timeline.

  • How can I change the palette of a BufferedImage

    How can I change the palette of a BufferedImage ?
    My image uses an IndexColorModel but I want to use a web safe palette.
    I can't see a way to make a setColorModel() to my image.
    Any ideas ?
    Thanks...

    import java.awt.*;
    import java.awt.event.*;
    import java.awt.image.*;
    import java.io.*;
    import java.net.*;
    import javax.imageio.*;
    import javax.swing.*;
    public class ICMExample extends JComponent {
        private BufferedImage original, copy;
        private Point mouseLocation = new Point();
        public ICMExample(BufferedImage original, BufferedImage copy) {
            this.original = original;
            this.copy = copy;
            addMouseMotionListener(new MouseMotionAdapter(){
                public void mouseDragged(MouseEvent e) {
                    mouseLocation = e.getPoint();
                    repaint();
        public Dimension getPreferredSize() {
            return new Dimension(original.getWidth(), original.getHeight());
        protected void paintComponent(Graphics g) {
            super.paintComponent(g);
            Graphics2D g2 = (Graphics2D) g;
            g2.drawRenderedImage(original, null);
            Shape oldClip = g2.getClip();
            g2.clipRect(0, 0, mouseLocation.x, Integer.MAX_VALUE);
            g2.drawRenderedImage(copy, null);
            g2.setClip(oldClip);
        public static void main(String[] args) throws IOException {
            URL url = new URL("http://weblogs.java.net/jag/Image54-large.jpeg");
            BufferedImage original = ImageIO.read(url);
            JComponent app = new ICMExample(original, makeICMVersion(original));
            final JFrame f = new JFrame("Drag mouse over image");
                f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                f.getContentPane().add(app);
                f.pack();
                SwingUtilities.invokeLater(new Runnable(){
                    public void run() {
                        f.setLocationRelativeTo(null);
                        f.setVisible(true);
        static BufferedImage makeICMVersion(BufferedImage original) {
            int w = original.getWidth();
            int h = original.getHeight();
            IndexColorModel icm = createICM();
            BufferedImage copy = new BufferedImage(w, h, BufferedImage.TYPE_BYTE_INDEXED, icm);
            Graphics2D g = copy.createGraphics();
            g.drawRenderedImage(original, null);
            g.dispose();
            return copy;
        static IndexColorModel createICM() {
            byte MAX = (byte) 255;
            byte[] r = {MAX, MAX, MAX, MAX, 0, 0, 0, 0};
            byte[] g = {MAX, MAX, 0, 0, MAX, MAX, 0, 0};
            byte[] b = {MAX, 0, MAX, 0, MAX, 0, MAX, 0};
            return new IndexColorModel(3, 8, r, g, b);
    }

  • Can I add a JPanel in JScrollPane?

    Can I add a JPanel in JScrollPane?
    If I added,components in the JPanel can effect the JScrollPane?
    thanks!

    Can I add a JPanel in JScrollPane?yes you can - it is meant for this.
    If I added,components in the JPanel can effect the
    JScrollPane?if you mean affect like focusing and scrolling to a certain place - the answer is yes, you have to look the right functions in each component you insert to the panel.

  • Can't render selections

    Hi,
    I can't render selections under yellow render indicators in the timeline with the Render Selection command, but it's possible to render the same clips when setting in and out and use Render In to Out. But rendering a selection under a red indicator using Render Selections was possible.
    Am I missing something or have anybody  experienced something like that?
    I am using Premiere Pro CC 7.2.1 (4) on Mac and PC
    Cheers
    Kim

    Hi Kim DT,
    Thanks for posting on Adobe forums,
    Please check this post, It will answer your query.
    http://blogs.adobe.com/premierepro/2011/02/red-yellow-and-green-render-bars.html
    With that preparatory definition out of the way, what do the colored bars mean?
    green: This segment of the sequence has a rendered preview file associated with it. Playback will play using the rendered preview file. Playback at full quality is certain to be in real time.
    yellow: This segment of the sequence does not have a rendered preview file associated with it. Playback will play by rendering each frame just before the CTI reaches it. Playback at full quality will probably be in real time (but it might not be).
    red: This segment of the sequence does not have a rendered preview file associated with it. Playback will play by rendering each frame just before the CTI reaches it. Playback at full quality will probably not be in real time (but it might be).
    Regards,
    Sandeep

  • Ask your question.Can't render get File error access denied. Whats causing this? FCP 7.0.3

    I Can't render get File error access denied. Whats causing this? FCP 7.0.3

    Its an was update from an earlier version.
    What earlier version?
    And you're saying when you using File>Import>File and select a JPEG you get the error message?
    You can't or shouldn't import MP3s into FCP.
    Have you try creating a new porject and importing into that?

  • Can I render Videos with my GPU? With AME or Adobe Premiere?

    Hey guys:
    I record xbox gameplays and post them on youtube. although, my question is can i render my videos with my GPU instead of my CPU with AME or Adobe Premiere and if i can i would like to know please. i usually record 25-40 minute long videos and i like to to render them at maximun depth so they can look nice and crisp but each video is taking around 12 to 15 hours to render.

    Try File > Export > Media straight from Premiere Pro instead of the queue in AME. You do not need to check Maximum Bit Depth when you're exporting directly from Premiere Pro which uses the GPU for certain processes, including scaling.

  • Can video can be shown inside JPanel ?

    Can video can be shown inside JPanel ? is there any example can do this ?

    Several information can be found on this topic.
    You can add video on JFrame, JInternalFrame so why not on JPanel ?
    For more information you can shearch examples in the Sun's JMF examples.
    I try to use video in JInternalFrame, but the frame rate is very bad ... so if you have solution... your are welcome.
    Good luck!

Maybe you are looking for