How  to  save  content of a  whole  swing  page

Hi everyone ..
can any of u tell me ,how to save contents of a java swing page in a single file with all components viz . textfield,textarea,JTable,JPanel etc .. with their respective formatting ie.e Font,Color etc ..
Plz let me know it soon .. its very urgent ..
Can I save it as Screenshot or Jpeg Image .. or how to go about it .
Mohit

Sure: see below!
WARNING: this code will not compile as is because it uses some other classes from my personal code library (FileUtil & StringUtil). The particular methods of those classes which are used below are trivial methods that anyone can write, which is is why I have not posted them as well. So, to get the code below to compile, you can
a) write your own versions of these classes or
b) simply add the necessary methods to this class or
c) simply comment out their usage (in the case of StringUtil, which is just used for arg checking)
But if you still want me to post them, then I can post the relevant fragments of those classes.
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import java.io.*;
import javax.imageio.*;
import javax.swing.*;
import bb.io.FileUtil;
import bb.util.StringUtil;
* Class which supports taking screen shots of the entire desktop, AWT Components, or Swing JComponents.
* This functionality is implemented in a series of <code>take</code> methods, each of which returns a BufferedImage.
* This class also offers convenience <code>write</code> methods for storing BufferedImages to files.
* <p>
* The images taken by this class should be the precise images seen on the screen.
* <b>However, the images written to files may deviate from the originals.</b>
* One obvious cause is limitations of the chosen file format (especially with lossy formats like jpeg).
* A subtle issue can occur, however, even when using lossless formats like png:
* if the file is subsequently opened by another application,
* that application may rescale the image, which can often cause visible artifacts.
* <blockquote>
*     To see this last problem on Windows XP,
*     call {@link #take()} which returns an image of the entire desktop and write it to a file,
*     and then open the file with XP's default graphics file viewer ("Windows Picture And Fax Viewer").
*     This program shrinks the desktop image in order to fit it inside the program's window,
*     and rescaling artifacts are readily seen, especially if the desktop image has any kind of text in it.
*     If "Windows Picture And Fax Viewer" instead cropped the image or had a scroll pane, then this should not happen.
* </blockquote>
* <p>
* Acknowledgement: this class was inspired by the program
* <a href="http://www.discoverteenergy.com/files/ScreenImage.java">ScreenImage</a>.
* Differences from the above program:
* <ol>
*  <li>this class uses {@link BufferedImage#TYPE_INT_ARGB} instead of {@link BufferedImage#TYPE_INT_RGB} in order to preserve alpha</li>
*  <li>this class's {@link #formatNameDefault default image file format} is PNG instead of JPEG</li>
*  <li>this class's <code>take</code> methods simply take snapshots and never have the side effect of writing image files</li>
*  <li>this class added a version of <code>take</code> which can get a snapshot of a region of a Component</li>
*  <li>
*          when taking a snapshot of a region of a Component or JComponent,
*          the Rectangle that specifies the region always has coordinates relative to the origin of the item
*  </li>
* </ol>
* See also:
* <a href="http://forum.java.sun.com/thread.jspa?forumID=57&threadID=597936">forum discussion #1 on screen shots</a>
* <a href="http://forum.java.sun.com/thread.jspa?forumID=256&threadID=529933">forum discussion #2 on screen shots</a>
* <a href="http://forum.java.sun.com/thread.jspa?forumID=57&threadID=622393">forum discussion #3 on screen shots</a>.
* <p>
* It might appear that this class is multithread safe
* because it is immutable (both its immediate state, as well as the deep state of its fields).
* However, typical Java gui code is not multithread safe, in particular, once a component has been realized
* it should only be accessed by the event dispatch thread
* (see <a href="http://java.sun.com/developer/JDCTechTips/2003/tt1208.html#1">Multithreading In Swing</a>
* and <a href="http://java.sun.com/developer/JDCTechTips/2004/tt0611.html#1">More Multithreading In Swing</a>).
* So, in order to enforce that requirement, all methods of this class which deal with components
* require the calling thread to be the event dispatch thread.
* See the javadocs of each method for its thread requirements.
* <p>
* @author bbatman
public class ScreenShot {
     // -------------------- constants --------------------
     * Defines the image type for the BufferedImages that will create when taking snapshots.
     * The current value is {@link BufferedImage#TYPE_INT_ARGB}, which was chosen because
     * <ol>
     *  <li>the 'A' in its name means that it preserves any alpha in the image (cannot use the "non-A" types)</li>
     *  <li>the "_INT" types are the fastest types (the "BYTE" types are slower)
     * </ol>
     * @see <a href="http://forum.java.sun.com/thread.jspa?threadID=709109&tstart=0">this forum posting</a>
     private static final int imageType = BufferedImage.TYPE_INT_ARGB;
     * Default value for the graphics file format that will be written by this class.
     * The current value is "png" because the PNG format is by far the best lossless format currently available.
     * Furthermore, java cannot write to GIF anyways (only read).
     * <p>
     * @see <a href="http://www.w3.org/TR/PNG/">Portable Network Graphics (PNG) Specification (Second Edition)</a>
     * @see <a href="http://www.w3.org/QA/Tips/png-gif">GIF or PNG</a>
     * @see <a href="http://www.libpng.org/pub/png/">PNG Home Site</a>
     public static final String formatNameDefault = "png";
     // -------------------- take --------------------
     // desktop versions:
     * Takes a screen shot of the entire desktop.
     * <p>
     * Any thread may call this method.
     * <p>
     * @return a BufferedImage representing the entire screen
     * @throws AWTException if the platform configuration does not allow low-level input control. This exception is always thrown when GraphicsEnvironment.isHeadless() returns true
     * @throws SecurityException if createRobot permission is not granted
     public static BufferedImage take() throws AWTException, SecurityException {
          Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
          Rectangle region = new Rectangle(0, 0, d.width, d.height);
          return take(region);
     * Takes a screen shot of the specified region of the desktop.
     * <p>
     * Any thread may call this method.
     * <p>
     * @param region the Rectangle within the screen that will be captured
     * @return a BufferedImage representing the specified region within the screen
     * @throws IllegalArgumentException if region == null; region's width and height are not greater than zero
     * @throws AWTException if the platform configuration does not allow low-level input control. This exception is always thrown when GraphicsEnvironment.isHeadless() returns true
     * @throws SecurityException if createRobot permission is not granted
     public static BufferedImage take(Rectangle region) throws IllegalArgumentException, AWTException, SecurityException {
          if (region == null) throw new IllegalArgumentException("region == null");
          return new Robot().createScreenCapture( region );     // altho not currently mentioned in its javadocs, if you look at its source code, the Robot class is synchronized so it must be multithread safe, which is why any thread should be able to call this method
     // AWT Component versions:
     * Takes a screen shot of that part of the desktop whose area is where component lies.
     * Any other gui elements in this area, including ones which may lie on top of component,
     * will be included, since the result always reflects the current desktop view.
     * <p>
     * Only {@link EventQueue}'s {@link EventQueue#isDispatchThread dispatch thread} may call this method.
     * <p>
     * @param component AWT Component to take a screen shot of
     * @return a BufferedImage representing component
     * @throws IllegalArgumentException if component == null; component's width and height are not greater than zero
     * @throws IllegalStateException if calling thread is not EventQueue's dispatch thread
     * @throws AWTException if the platform configuration does not allow low-level input control. This exception is always thrown when GraphicsEnvironment.isHeadless() returns true
     * @throws SecurityException if createRobot permission is not granted
     public static BufferedImage take(Component component) throws IllegalArgumentException, IllegalStateException, AWTException, SecurityException {
          if (component == null) throw new IllegalArgumentException("component == null");
          if (!EventQueue.isDispatchThread()) throw new IllegalStateException("calling thread (" + Thread.currentThread().toString() + ") is not EventQueue's dispatch thread");
          Rectangle region = component.getBounds();
          region.x = 0;     // CRITICAL: this and the next line are what make region relative to component
          region.y = 0;
          return take(component, region);
     * Takes a screen shot of that part of the desktop whose area is the region relative to where component lies.
     * Any other gui elements in this area, including ones which may lie on top of component,
     * will be included, since the result always reflects the current desktop view.
     * <p>
     * Only {@link EventQueue}'s {@link EventQueue#isDispatchThread dispatch thread} may call this method.
     * <p>
     * @param component AWT Component to take a screen shot of
     * @param region the Rectangle <i>relative to</i> component that will be captured
     * @return a BufferedImage representing component
     * @throws IllegalArgumentException if component == null; component's width and height are not greater than zero; region == null
     * @throws IllegalStateException if calling thread is not EventQueue's dispatch thread
     * @throws AWTException if the platform configuration does not allow low-level input control. This exception is always thrown when GraphicsEnvironment.isHeadless() returns true
     * @throws SecurityException if createRobot permission is not granted
     public static BufferedImage take(Component component, Rectangle region) throws IllegalArgumentException, IllegalStateException, AWTException, SecurityException {
          if (component == null) throw new IllegalArgumentException("component == null");
          if (region == null) throw new IllegalArgumentException("region == null");
          if (!EventQueue.isDispatchThread()) throw new IllegalStateException("calling thread (" + Thread.currentThread().toString() + ") is not EventQueue's dispatch thread");
          Point p = new Point(0, 0);
          SwingUtilities.convertPointToScreen(p, component);
          region.x += p.x;
          region.y += p.y;
          return take(region);
     // Swing JComponent versions:
     * Takes a screen shot of <i>just</i> jcomponent
     * (no other gui elements will be present in the result).
     * <p>
     * Only {@link EventQueue}'s {@link EventQueue#isDispatchThread dispatch thread} may call this method.
     * <p>
     * @param jcomponent Swing JComponent to take a screen shot of
     * @return a BufferedImage representing jcomponent
     * @throws IllegalArgumentException if jcomponent == null
     * @throws IllegalStateException if calling thread is not EventQueue's dispatch thread
     public static BufferedImage take(JComponent jcomponent) throws IllegalArgumentException, IllegalStateException {
          if (jcomponent == null) throw new IllegalArgumentException("jcomponent == null");
          if (!EventQueue.isDispatchThread()) throw new IllegalStateException("calling thread (" + Thread.currentThread().toString() + ") is not EventQueue's dispatch thread");
          Dimension d = jcomponent.getSize();
          Rectangle region = new Rectangle(0, 0, d.width, d.height);
          return take(jcomponent, region);
     * Takes a screen shot of <i>just</i> the specified region of jcomponent
     * (no other gui elements will be present in the result).
     * <p>
     * Only {@link EventQueue}'s {@link EventQueue#isDispatchThread dispatch thread} may call this method.
     * <p>
     * @param jcomponent Swing JComponent to take a screen shot of
     * @param region the Rectangle <i>relative to</i> jcomponent that will be captured
     * @return a BufferedImage representing the region within jcomponent
     * @throws IllegalArgumentException if jcomponent == null; region == null
     * @throws IllegalStateException if calling thread is not EventQueue's dispatch thread
     public static BufferedImage take(JComponent jcomponent, Rectangle region) throws IllegalArgumentException, IllegalStateException {
          if (jcomponent == null) throw new IllegalArgumentException("jcomponent == null");
          if (region == null) throw new IllegalArgumentException("region == null");
          if (!EventQueue.isDispatchThread()) throw new IllegalStateException("calling thread (" + Thread.currentThread().toString() + ") is not EventQueue's dispatch thread");
          boolean opaquenessOriginal = jcomponent.isOpaque();
          Graphics2D g2d = null;
          try {
               jcomponent.setOpaque( true );
               BufferedImage image = new BufferedImage(region.width, region.height, imageType);
               g2d = image.createGraphics();
               g2d.translate(-region.x, -region.y) ;     // CRITICAL: this and the next line are what make region relative to component
               g2d.setClip( region );
               jcomponent.paint( g2d );
               return image;
          finally {
               jcomponent.setOpaque( opaquenessOriginal );
               if (g2d != null) g2d.dispose();
     // -------------------- write --------------------
     * Writes image to a newly created File named fileName.
     * The graphics format will either be the extension found in fileName
     * or else {@link #formatNameDefault} if no extension exists.
     * <p>
     * Any thread may call this method.
     * <p>
     * @param image the BufferedImage to be written
     * @param fileName name of the File that will write image to
     * @throws IllegalArgumentException if image == null; fileName is blank
     * @throws IOException if an I/O problem occurs
     public static void write(BufferedImage image, String fileName) throws IllegalArgumentException, IOException {
          if (image == null) throw new IllegalArgumentException("image == null");
          if (StringUtil.isBlank(fileName)) throw new IllegalArgumentException("fileName is blank");
          File file = new File(fileName);
          String formatName = FileUtil.getExtension(file);
          if (formatName.length() == 0) formatName = formatNameDefault;
          write(image, formatName, file);
     * Writes image to file in the format specified by formatName.
     * <p>
     * Any thread may call this method.
     * <p>
     * @param image the BufferedImage to be written
     * @param formatName the graphics file format (e.g. "pnj", "jpeg", etc);
     * must be in the same set of values supported by the formatName arg of {@link ImageIO#write(RenderedImage, String, File)}
     * @param file the File that will write image to
     * @throws IllegalArgumentException if image == null; type is blank; file == null
     * @throws IOException if an I/O problem occurs
     public static void write(BufferedImage image, String formatName, File file) throws IllegalArgumentException, IOException {
          if (image == null) throw new IllegalArgumentException("image == null");
          if (StringUtil.isBlank(formatName)) throw new IllegalArgumentException("formatName is blank");
          if (file == null) throw new IllegalArgumentException("file == null");
          ImageIO.write(image, formatName, file);
     // -------------------- Test (inner class) --------------------
     * An inner class that consists solely of test code for the parent class.
     * <p>
     * Putting all the test code in this inner class (rather than a <code>main</code> method of the parent class) has the following benefits:
     * <ol>
     *  <li>test code is cleanly separated from working code</li>
     *  <li>any <code>main</code> method in the parent class is now reserved for a true program entry point</li>
     *  <li>test code may be easily excluded from the shipping product by removing all the Test class files (e.g. on Windoze, delete all files that end with <code>$Test.class</code>)</li>
     * </ol>
     * Putting all the test code in this inner class (rather than a shadow external class) has the following benefits:
     * <ol>
     *  <li>non-public members may be accessed</li>
     *  <li>the test code lives very close to (so is easy to find) yet is distinct from the working code</li>
     *  <li>there is no need to set up a test package structure</li>
     * </ol>
     public static class Test {
          public static void main(String[] args) throws Exception {
               Gui gui = new Gui();
               EventQueue.invokeLater( gui.getBuilder() );
               new Timer(1000, gui.getTimerActionListener()).start();
          private static class Gui {
               private Frame frame;
               private TextField textField;
               private JFrame jframe;
               private JLabel jlabel;
               private JPanel jpanel;
               private int count = 0;
               private Runnable getBuilder() {
                    return new Runnable() {
                         public void run() {
                              System.out.println("Creating a Frame with AWT widgets inside...");
                              frame = new Frame("ScreenShot.Test.main Frame");
                              textField = new TextField();
                              textField.setText( "Waiting for the screen shot process to automatically start..." );
                              frame.add(textField);                              
                              frame.pack();
                              frame.setLocationRelativeTo(null);     // null will center it in the middle of the screen
                              frame.setVisible(true);
                              System.out.println("Creating a JFrame with Swing widgets inside...");
                              jframe = new JFrame("ScreenShot.Test.main JFrame");
                              jlabel = new JLabel(
                                   "<html>" +
                                        "To be, or not to be: that is the question:" + "<br>" +
                                        "Whether 'tis nobler in the mind to suffer" + "<br>" +
                                        "The slings and arrows of outrageous fortune," + "<br>" +
                                        "Or to take arms against a sea of troubles," + "<br>" +
                                        "And by opposing end them?" + "<br>" +
                                        "To die: to sleep; No more;" + "<br>" +
                                        "and by a sleep to say we end" + "<br>" +
                                        "The heart-ache and the thousand natural shocks" + "<br>" +
                                        "That flesh is heir to," + "<br>" +
                                        "'tis a consummation Devoutly to be wish'd." + "<br>" +
                                   "</html>"
                              jpanel = new JPanel();
                              jpanel.setBorder( BorderFactory.createEmptyBorder(20, 20, 20, 20) );
                              jpanel.add(jlabel);
                              jframe.getContentPane().add(jpanel);
                              jframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                              jframe.pack();
                              Point p = frame.getLocation();
                              p.translate(0, frame.getSize().height  + 10);
                              jframe.setLocation(p);
                              jframe.setVisible(true);
               private ActionListener getTimerActionListener() {
                    return new ActionListener() {
                         public void actionPerformed(ActionEvent evt) {
                              try {
                                   switch (count++) {
                                        case 0:
                                             displayMessage("Taking a screen shot of the entire desktop...");
                                             ScreenShot.write( ScreenShot.take(), "desktop.png" );
                                             break;
                                        case 1:
                                             displayMessage("Taking a screen shot of the central rectangle of the desktop...");
                                             Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
                                             Rectangle region = getCenteredRectangle(d);
                                             ScreenShot.write( ScreenShot.take(region), "desktopCenteredRectangle.png" );
                                             break;
                                        case 2:
                                             displayMessage("Taking a screen shot of the TextField...");
                                             ScreenShot.write( ScreenShot.take(textField), "textField.png" );
                                             break;
                                        case 3:
                                             displayMessage("Taking a screen shot of the central rectangle of the TextField...");
                                             d = textField.getSize();
                                             region = getCenteredRectangle(d);
                                             ScreenShot.write( ScreenShot.take(textField, region), "textFieldCenteredRectangle.png" );
                                             break;
                                        case 4:
                                             displayMessage("Taking a screen shot of the JLabel...");
                                             ScreenShot.write( ScreenShot.take(jlabel), "jlabel.png" );
                                             break;
                                        case 5:
                                             displayMessage("Taking a screen shot of the central rectangle of the JLabel...");
                                             d = jpanel.getSize();
                                             region = getCenteredRectangle(d);
                                             ScreenShot.write( ScreenShot.take(jpanel, region), "jpanelCenteredRectangle.png" );
                                             break;
                                        default:
                                             System.exit(0);
                                             break;
                              catch (Throwable t) {
                                   t.printStackTrace(System.err);
                         private void displayMessage(String text) {
                              System.out.println(text);
                              textField.setText(text);
                              frame.pack();
                              frame.invalidate();
                         private Rectangle getCenteredRectangle(Dimension d) {
                              int x = d.width / 4;
                              int y = d.height / 4;
                              int width = d.width / 2;
                              int height = d.height / 2;
                              return new Rectangle(x, y, width, height);
}

Similar Messages

  • How to save content typed in textfield only as lowercase in repository?

    How to save content typed in textfield only as lowercase in repository?
    Suppose we have a textfield in a component dialog. Irrespective of how enduser enters the data in the textfield, lower/mixed/upper case, it should always be saved as lowercase in the repository.

    You have 2 options:
    * Frontend: You adjust the javascript, so the user can only enter lowercase characters
    * Server-side: Implement a SlingPostProcessor to change the data to lowercase before it is persisted (see http://sling.apache.org/apidocs/sling6/org/apache/sling/servlets/post/SlingPostProcessor.h tml)
    Jörg

  • How to pull content from div on one page to div on another page

    Hi all,
    I would like to pull content from the divs on page to divs on another page (so that I only have to update information on one page).
    Could anybody give me a tip on where to read about this/how to do this? I am not expecting the final answer, just a clue on where to start looking for how to get startet.
    Thanks in advance for any answers.
    Best regards,
    Ivan
    www.colombiareiser.no

    Try reading on DW Spry html data sets. The Spry HTML data set allows users to use standard HTML tables and other structured markup as a data source.
    http://labs.adobe.com/technologies/spry/articles/html_dataset/index.html
    http://labs.adobe.com/technologies/spry/docs.html
    Regards,
    Vinay

  • How to set content type for a JSF page

    Hi,
    I want to know is there any way we can specify the content type of a JSF page, like in JSPs we have the page attribute <%@ page contentType="application/vnd.ms-excel" %>
    In JSP we can create a html table with values and if we specify the contenType as application/vnd.ms-excel, we would get an excel file generated.
    But do we have something similar to this is JSF, as I am using Facelets I cannot use page directive in the xhtml file.
    I tried setting the content type in MangedBean's action as follows
    ((HttpServletResponse)FacesContext.getCurrentInstance().getExternalContext().getResponse()).setContentType("application/vnd.ms-excel"); but it did'nt work.
    Thanks in advance.

    //add related mutip-part to combine parts
    MimeMultipart multipart = new MimeMultipart("related");
    //attach a pdf
    messageBodyPart = new MimeBodyPart();
    fds = new FileDataSource("h:/something.pdf");
    messageBodyPart.setDataHandler(new DataHandler(fds));
    messageBodyPart.setFileName(fds.getName());
    multipart.addBodyPart(messageBodyPart);
    //add multipart to the message
    message.setContent(multipart);
    //send message
    Transport.send(message);

  • How to save contents of two different rich edit box into single rtf file in windows 8.1 app

    Developer, I have requirement to save registration data into rtf file.. These can only be done by if I put rich edit box to fill the data.. Now if I am going to write the code for saving the data of different rich edit box into one particular file, it
    only saves the data of last rich edit box.. So plzz suggest that how can I save the contents of different rich edit box together into one rtf file.

    Ok Nishant, just did some quick research, since rtf file is unlike txt file, we cannot simply directly write some content to the rtf.
    You can try to find some third party code that can help you insert text into rtf file or you would like to load the content from rtf out to the richeditbox and merge them to one richeditbox and then save back to the file.
    You could like to see how to read/save rtf file sample from:
    RichEditBox class
    --James
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • How to save contents of a structure into a field (of type LRAW) of a table?

    Hi,
    I've got a structure, with a few fields, some being char fields and some of type decimals and would like to save the contents into a field of a table, which is of type LRAW.
    I know that I've got to also update the table with the correct length of the value stored in LRAW, and have done that, but it seems to have lost the end bits of the LRAW field.
    Also, can I also find out how I can then retrieve the LRAW value after it's being saved? This needs to be done as later on, we would have to move the values from LRAW into the initial structure it came from.
    Thanks for your help!
    Regards,
    Adeline.

    Use MOVE command to move the contents of the stucture fields to the Wok area of the Internal table and then APPEND it to the Internal table

  • How to save contents of a JTable? Pls Help

    Can someone tell me how can I save the contents of a table in a file and load them back after I click a load file button in menuBar.
    Any help would be appriciated.

    Actually, I first wanted to get Window Pop-up asking for a file name and then after file name is entered user should click on save button and then all the data entered in the table should be saved.
    thanks

  • How to share content across a whole family?

    I know there are other threads related to this, but I'm really trying to understand how to manage iTunes DRM, Home Sharing, Match, etc., across my family's ecosystem of Macs, iPhones, iPods and iPads. I seem to think the following apply:
    - up to 5 "computers" (does this mean OSX devices but not iOS devices?) can share DRM content
    - up to 10 "devices" can share Match content (presume this means content I've uploaded, not Apple DRM content I've purchased in iTunes Store)
    So here's what I am trying to figure out:
    1. Let's say we have 5 "computers" that are running OSX (iMac and 4 Macbooks), can then all of our iOS devices -- iPads (2), iPhones (2) and iPod Touches (3) -- have the same DRM content on them? So if I purchased the movie "Monsters Inc" from the iTunes Store, can it be in iTunes on all 5 OSX devices plus any of the 7 iOS devices I wish to have it on?
    2. If the answer is "NO" to #1, can I selectively apply where the content goes to stay within the maximums? For example, let's say I have "Monsters Inc" on some of the devices and the movie "Cars" on others such that, while I have more devices accessing my DRM content, no one DRM item (movie, song, etc.) is across more than is allowed?
    3. Lastly, if we add a 6th OSX "computer" then I presume to add an DRM content it would have to be re-purchased under a separeate iTunes account? Or, said another way, there's really no way to have more than 5 computers on the same iTunes account?
    I am hoping Apple is making this all easy to do as they ask all of us to buy more of their products, but without the ability to access DRM content on new devices like iPad Mini, there's really no reason to buy one.
    Thanks for any help

    iTunes Store: Associating a device or computer to your Apple ID - http://support.apple.com/kb/HT4627 -  "Your Apple ID can have up to 10 devices and computers (combined) associated with it. Each computer must also be authorized using the same Apple ID. Once a device or computer is associated with your Apple ID, you cannot associate that device or computer with another Apple ID for 90 days."
    iTunes Store: About authorization and deauthorization - http://support.apple.com/kb/HT1420
    Various paragraphs talking about restrictions:
    http://www.apple.com/legal/itunes/us/terms.html > USAGE RULES

  • How to save contents of JPanel to an image file

    Hi,
    I am using a JPanel to display some primitive shapes(line, circle,etc.) and I need to save the contents of this panel to disk as an image file (JPEG, bitmap, TIFF, etc.). Have searched jdc but've found no feasible results. I would really appreciate a sample code for this job.
    Thanks in advance.
    -Burak

    Got it ...i just forgot the 3rd line:
    fos = new FileOutputStream("c:\\majjooo.jpg");
    JPEGImageEncoder enc = JPEGCodec.createJPEGEncoder(fos);
    enc.encode(img);but am still having a problem is that the picture is black ...eventhough the panel has contents and i can see it but the picture has nothing but pitch black ...what do you think ??

  • How to save contents of a JTextArea to a file without the newline blocks?

    Hello everyone
    I have created a GUI with a JTextArea and a button to save the contents of the JTextArea to a text file. I am working on a windows platform. Problem is that when saving the contents to the file, the newline block appears within the file ignoring the newline in the JTextArea.
    Is there a way of saving these contents the way they appear in the JTextArea preserving the format they are displayed? I want to create a file that looks exactly the way my JTextArea looks like.
    Up to the moment i am using the following code which produces a rather confusing file:
    save.addActionListener(
                        new ActionListener() {
                             public void actionPerformed(ActionEvent e) {
                                  String textCaptured = textArea.getText();
                                  File file = new File("Log.txt");
                                  try {
                                       BufferedWriter out = new BufferedWriter(new FileWriter(file));
                                       out.write(textCaptured);
                                       out.flush();
                                       out.close();
                                  } catch (IOException e1) {
                                       // TODO Auto-generated catch block
                                       e1.printStackTrace();
                                  finally{
                                       JOptionPane.showMessageDialog(null,"Your log file has been created");
              );Thank you all in advance
    Christophoros

    Thanks uncle_alice.
    Your solution worked like a charm :)
    Have a nice day
    To anyone who might face similar problems heres the code:
    File file = new File("Log.txt");
                                  try {
                                       BufferedWriter out = new BufferedWriter(new FileWriter(file));
                                       textArea.write(out);
                                       out.flush();
                                       out.close();
                                  } catch (IOException e1) {
                                       // TODO Auto-generated catch block
                                       e1.printStackTrace();

  • How to save content of JPanel into jpeg or png file

    I have to independent classes: Class A and Class B. Each class constructs its own graphical objects:
    Class A {
    //do something
    public void paintComponent(Graphics g)
    int x = 0;
    int y = 0;
    int w = getSize().width;
    int h = getSize().height;
    bi = new BufferedImage(
    w,h,100,BufferedImage.TYPE_INT_RGB);
    g2d = bi.createGraphics();
    // draw lines
    g2d.drawImage(bi,0,0,ww,hh, this);
    Class B {
    int x = 0;
    int y = 0;
    int w = getSize().width;
    int h = getSize().height;
    bi = new BufferedImage(
    w,h,100,BufferedImage.TYPE_INT_RGB);
    g2d = bi.createGraphics();
    // draw lines
    g2d.drawImage(bi,0,0,ww,hh, this);
    Two buffered images get properly displayed within JPanel component. However, I need to save two those results into one file. If I add saving file routine into every class, at best I can only get them to be in two different files.
    Please let me know if anyone can help me with this problem.
    Thanks,
    Jack

    You didn't mention what should be the format of file that the combines the images. Here are two options:
    1. Create another BufferedImage, and draw the BufferedImages from class A and B over this BufferedImage and save it as JPEG or PNG.
    In each of the class, you can add a method like getBufferedImage(), which would return the local BufferedImage. A third class, say class C, needs to call this method in each of the classes, and then draw the BufferedImages returned by these methods over another BufferedImage. Save this BufferedImage as a JPEG or PNG.
    A disadvantage of this approach is that you can't easily retrieve the individual images from the resulting file.
    2. Create a single zip file by adding the individual JPEG/ PNG images created from the BufferedImage in class A and B.
    Here is an example that creates single zip file of JPEG images from an array of BufferedImageObjects:
    public static void zip(String outfile, BufferedImage bufimage[]){
         if(bufimage == null) return;
         try{
             File of = outfile.endsWith(".zip")? new File(outfile): new File(outfile+".zip");
             FileOutputStream fos = new FileOutputStream(of);
             ZipOutputStream zos = new ZipOutputStream(fos);
             for(int i=0;i<bufimage.length;i++){
                 try{
                    ByteArrayOutputStream boutstream = new ByteArrayOutputStream();
                    JPEGImageEncoder enc = JPEGCodec.createJPEGEncoder(boutstream);
                    enc.encode(bufimage);
    ZipEntry entry = new ZipEntry("bufimage"+(new Integer(i)).toString()+".jpg");
    entry.setMethod(ZipEntry.DEFLATED);
    zos.putNextEntry(entry);
    byte[] fileBuf = boutstream.toByteArray();
    zos.write(fileBuf,0,fileBuf.length);
    zos.closeEntry();
    } catch (Exception e){ e.printStackTrace();}
    zos.flush();
    zos.close();
    }catch(Exception e) {e.printStackTrace();}
    The above method uses the JPEG codec and the zip package, both of which available in J2SE. In other words, you need to import com.sun.image.codec.jpeg and java.util.zip packages.
    With this approach, you can easily retrieve the individual JPEGs using the java.util.zip package.

  • How to save contents in paintbox to .jpeg or any image file using Director?

    I'm having difficulty in our System using Director (THESIS) because one of the compilation we had is to save the drawings in the paintbox into an image file (.jpeg, .bmp, .png, etc). Is there someone who can help me? Please I really need to learn it before deploying the final System. Thanks much~

    You could try Valentin's image encoders:
    http://valentin.dasdeck.com/lingo/image_encoders/

  • JasperReports - how to save as PDF from Print Preview page?

    Hi all!
    How can I save reports created with JasperReperts (with iReport tool) as PDF?
    On print preview, when I select it is as PDF, and click on "save", nothing is saved. Also, I get NoClassDefFoundError despite I included all nessesry classes (did I?). Here are list of included classes
    jasperreports-1.2.7.jar;
    jasperreports-1.2.7-javaflow.jar;
    commons-beanutils-1.5.jar;
    commons-collections-2.1.jar;
    commons-logging-1.0.2.jar;
    commons-digester-1.7.jar;Here is my code:
    void printWithPreview() {
        try {
          JasperPrint print = JasperFillManager.fillReport(report, reportParam, conn);
          JasperViewer.viewReport(print, false);
          //byte[] pdfasbytes = JasperExportManager.exportReportToPdf(print); // can I use it somehow?
          JasperExportManager.exportReportToPdf(print);
        } catch (JRException e) {
          e.printStackTrace();
      }Can you help me with this?
    Also, I need to know, how to limit options "save as" only to PFD (on same Print Preview page)?
    Thank you in advance!

    Right!
    I was missing iText.jar.
    So, you need only this code to get report preview and feature to export to pdf, html and other formats:
    void printWithPreview() {
        try {
          JasperPrint print = JasperFillManager.fillReport(report, reportParam, conn);
          JasperViewer.viewReport(print, false);
          JasperExportManager.exportReportToPdf(print);
        } catch (JRException e) {
          e.printStackTrace();
      }You do not need to save it specificly to c: or other "hard coded" directory.
    Thanx 1000 times!!!

  • How to save the modified rows in jspx page usind adf default commit action

    Hi,
    We are displaying some columns of the database table in jspx page. Here we are using adf commit action to save these values to database which is updating all the rows by default. In this page there are some editable columns which the user can miodify. How can we update only these modified rows using default adf commit action. Also we want to update last_updated_date column of that particular row which is modified in the UI from backing bean .
    Can anyone please help us in solving this.
    Thanks in advance

    User,
    A key question - what are you using for the model layer (ADF Business Components, JPA, EJB, etc)?
    How are you determining that a "commit" action is updating rows (even those which haven't changed)?
    If you are using ADF Business Components - have a read in the documentation about history columns - the use case you describe (updating the last_udpdated_date column) is supported "out-of-the-box" for this.
    John

  • How to stretch content div to bottom of page.

    Been messing around with my site so much that I needed to create a new one.
    However, I can't get to stretch the content div to the bottom of the page if the content text doesn't fill the page.
    I have a footer at the bottom of the page that stretches the full width of the page, so I can't use the trick with the body background.
    I found a lot of results on the internet, but I seem to get a little lost.
    Can anyone help me?
    This is my HTML code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <!-- TemplateBeginEditable name="doctitle" -->
    <title>Schudden fansite</title>
    <!-- TemplateEndEditable -->
    <!-- TemplateBeginEditable name="head" -->
    <!-- TemplateEndEditable -->
    <link href="../css/Noorderzon.css" rel="stylesheet" type="text/css" /></head>
    <body class="oneColElsCtrHdr">
    <div id="container">
    <div id="header">
    <h1> </h1>
    <!-- end #header --></div>
    <div id="mainContent">
    <div id="nav"><a href="#" title="Home">Home</a> | <a href="#" title="Biography">Biography</a> | <a href="#" title="News &amp; Updates">News &amp; Updates</a> | <a href="#" title="Gallery">Gallery</a> | <a href="#" title="Portfolio Work">Portfolio Work</a> | <a href="#" title="Links">Links</a> | <a href="#" title="Contact">Contact</a></div>
    <p>Main Content</p>
    <p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Praesent aliquam,  justo convallis luctus rutrum, erat nulla fermentum diam, at nonummy quam  ante ac quam. Maecenas urna purus, fermentum id, molestie in, commodo  porttitor, felis. Nam blandit quam ut lacus. Quisque ornare risus quis  ligula. P</p>
        <h2> </h2>
        <p> </p>
    </div>
      <div id="footer">
        <p> </p>
      <!-- end #footer --></div>
    <!-- end #container --></div>
    </body>
    </html>
    And this is the CSS code:
    @charset "utf-8";
    body {
    padding: 0;
    text-align: center; /* this centers the container in IE 5* browsers. The text is then set to the left aligned default in the #container selector */
    color: #000000;
    font-family: Verdana, Arial, Helvetica, sans-serif;
    font-size: 9pt;
    background-color: #800000;
    margin-top: 0;
    margin-right: auto;
    margin-bottom: 0;
    margin-left: auto;
    height: 100%;
    body,td,th {
    font-size: 9pt;
    color: #333;
    /* Tips for Elastic layouts
    1. Since the elastic layouts overall sizing is based on the user's default fonts size, they are more unpredictable. Used correctly, they are also more accessible for those that need larger fonts size since the line length remains proportionate.
    2. Sizing of divs in this layout are based on the 100% font size in the body element. If you decrease the text size overall by using a font-size: 80% on the body element or the #container, remember that the entire layout will downsize proportionately. You may want to increase the widths of the various divs to compensate for this.
    3. If font sizing is changed in differing amounts on each div instead of on the overall design (ie: #sidebar1 is given a 70% font size and #mainContent is given an 85% font size), this will proportionately change each of the divs overall size. You may want to adjust based on your final font sizing.
    #container  {
    width: 100%;
    text-align: center; /* this overrides the text-align: center on the body element. */
    margin-top: 0;
    margin-right: auto;
    margin-bottom: 0;
    margin-left: auto;
    background-color: #800000;
    padding-bottom: 0px;
    top: 0px;
    bottom: 0px;
    height: 100%;
    #header  {
    width: 960px;
    padding-top: 0;
    padding-bottom: 0;
    height: 160px;
    margin-right: auto;
    margin-left: auto;
    background-color: #DDDDDD;
    background-image: url(../images/header.jpg);
    #header h1  {
    margin: 0; /* zeroing the margin of the last element in the #header div will avoid margin collapse - an unexplainable space between divs. If the div has a border around it, this is not necessary as that also avoids the margin collapse */
    padding: 10px 0; /* using padding instead of margin will allow you to keep the element away from the edges of the div */
    #mainContent  {
    width: 960px;
    margin-right: auto;
    margin-left: auto;
    padding-top: 0;
    padding-right: 0px;
    padding-bottom: 0;
    padding-left: 0px;
    background-image: url(../images/mainbg.jpg);
    height: 100%;
    #nav {
    text-align:center;
    margin-top:0px;
    font-family:Verdana, Arial, Helvetica, sans-serif;
    font-size:10pt;
    color:#000;
    font-weight:700;
    padding-top:9px;
    padding-bottom:10px;
    text-decoration:none;
    background-image: url(../images/mainbg.jpg);
    background-repeat: repeat;
    width: 960px;
    #nav a {
    background:#fff;
    color:#000;
    text-decoration:none;
    #nav a:active {
    background:#fff;
    color:#800000;
    #nav a:hover {
    background:#fff;
    color:#000;
    font-size:10pt;
    padding-bottom:2px;
    border-bottom-width: 3px;
    border-bottom-style: dotted;
    border-bottom-color: #800000;
    a:link {
    color: #000;
    a:hover {
    color: #800000;
    a:active {
    color: #369;
    a:visited {
    color: #369;
    #footer  {
    height: 100px;
    width: 100%;
    padding-top: 0;
    padding-bottom: 0;
    background-image: url(../images/bottom.png);
    margin-bottom: 0px;
    bottom: 0px;
    position: fixed;

    so Im having an issue that is similar but the fixes arent really working. Here is the site http://upeer.jordanselectronics.com/
    I've never worked with a page this short so it was never an issue but I want the content area to stretch 100 percent so it fills the browser window and pushes the footer to the bottom if the page is so short theres no scroll bar. I put height modifiers on the body, the wrapper(container) and the content div but it's still only as tall as the content in the content div.
    @charset "utf-8";
    body {
    font: 100%/1.4 Verdana, Arial, Helvetica, sans-serif;
    margin: 0;
    padding: 0;
    min-height: 100%;
    /* ~~ Element/tag selectors ~~ */
    ul, ol, dl { /* Due to variations between browsers, it's best practices to zero padding and margin on lists. For consistency, you can either specify the amounts you want here, or on the list items (LI, DT, DD) they contain. Remember that what you do here will cascade to the .nav list unless you write a more specific selector. */
    padding: 0;
    margin: 0;
    h1, h2, h3, h4, h5, h6, p {
    font-family: Arial, Helvetica, sans-serif;
    color: #333;
    font-size: 1em;
    a img { /* this selector removes the default blue border displayed in some browsers around an image when it is surrounded by a link */
    border: none;
    /* ~~ Styling for your site's links must remain in this order - including the group of selectors that create the hover effect. ~~ */
    a:link {
    color: #42413C;
    text-decoration: underline; /* unless you style your links to look extremely unique, it's best to provide underlines for quick visual identification */
    a:visited {
    color: #6E6C64;
    text-decoration: underline;
    a:hover, a:active, a:focus { /* this group of selectors will give a keyboard navigator the same hover experience as the person using a mouse. */
    text-decoration: none;
    /* ~~ this fixed width container surrounds the other divs ~~ */
    .container {
    width: 960px;
    margin: 0 auto;
    height: 100%;
    /* ~~ the header is not given a width. It will extend the full width of your layout. It contains an image placeholder that should be replaced with your own linked logo ~~ */
    .header {
    /* ~~ This is the layout information. ~~
    1) Padding is only placed on the top and/or bottom of the div. The elements within this div have padding on their sides. This saves you from any "box model math". Keep in mind, if you add any side padding or border to the div itself, it will be added to the width you define to create the *total* width. You may also choose to remove the padding on the element in the div and place a second div within it with no width and the padding necessary for your design.
    .content {
    background-image: url(contentbackground.png);
    padding: 25px;
    min-height: 100%;
    /* ~~ The footer ~~ */
    .footer {
    background-image: url(footerbackground.png);
    background-repeat: no-repeat;
    /* ~~ miscellaneous float/clear classes ~~ */
    .fltrt {  /* this class can be used to float an element right in your page. The floated element must precede the element it should be next to on the page. */
    float: right;
    margin-left: 8px;
    .fltlft { /* this class can be used to float an element left in your page. The floated element must precede the element it should be next to on the page. */
    float: left;
    margin-right: 8px;
    .clearfloat { /* this class can be placed on a <br /> or empty div as the final element following the last floated div (within the #container) if the #footer is removed or taken out of the #container */
    clear:both;
    height:0;
    font-size: 1px;
    line-height: 0px;
    .navbar {
    background-color: #F00;

Maybe you are looking for