Results 1 to 5 of 5
Like Tree1Likes
  • 1 Post By quad64bit

Thread: How to create a jbutton to save the jpanel as a jpeg??

  1. #1
    wet543dftgd is offline Member
    Join Date
    Jan 2012
    Posts
    2
    Rep Power
    0

    Post How to create a jbutton to save the jpanel as a jpeg??

    Hello, I am a beginner of java.
    I made a class to print out the calendar with jpanel. And I don't know how to create a jbutton to save the calendar as a jpg for the users.
    Does anyone can tell me how to do that? Thanks in advance!!!

  2. #2
    quad64bit's Avatar
    quad64bit is offline Moderator
    Join Date
    Jul 2009
    Location
    VA
    Posts
    1,323
    Rep Power
    7

    Default Re: How to create a jbutton to save the jpanel as a jpeg??

    Button is easy.
    Java Code:
    JButton button = new JButton("Click Me!");
    You will need to add an action listener to the button to tell java what to do when the user clicks it. Here is a tutorial for buttons: tutorial

    Now as far as saving a jpeg... How are you displaying a calendar? Are you drawing on a JPanel with Java2D? You can draw to a BufferedImage and use ImageIO to write that in your desired format.
    Eranga likes this.

  3. #3
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default Re: How to create a jbutton to save the jpanel as a jpeg??

    Work on one step at a time. Because when comes to a button (actually any control) there are a lot to learn, specially with actions listeners. So you better do some considerable amount of work on it.

  4. #4
    wet543dftgd is offline Member
    Join Date
    Jan 2012
    Posts
    2
    Rep Power
    0

    Default Re: How to create a jbutton to save the jpanel as a jpeg??

    Thank you for the help, I now have a clear direction to do that

  5. #5
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

Similar Threads

  1. Save a JPanel in NetBeans 7.0.1
    By mad72584 in forum New To Java
    Replies: 4
    Last Post: 08-17-2011, 02:16 PM
  2. Open JPanel with JButton
    By web_dev in forum New To Java
    Replies: 7
    Last Post: 06-13-2011, 11:25 PM
  3. Adding JPEG to JButton Child
    By rsieberg in forum AWT / Swing
    Replies: 3
    Last Post: 03-27-2011, 09:33 PM
  4. Replies: 1
    Last Post: 11-09-2010, 10:28 AM
  5. Save image as JPEG
    By aartheesrini in forum Java Applets
    Replies: 1
    Last Post: 03-16-2009, 06:56 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •