Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3439382
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T08:18:12+00:00 2026-05-18T08:18:12+00:00

I need to draw the content of a component and all its subcomponents in

  • 0

I need to draw the content of a component and all its subcomponents in a bitmap.
The following code works perfectly if i want to draw the entire component :

public void printComponent(Component c, String format, String filename) throws IOException {
// Create a renderable image with the same width and height as the component
BufferedImage image = new BufferedImage(c.getWidth(), c.getHeight(), BufferedImage.TYPE_INT_ARGB);

    // Render the component and all its sub components
    c.paintAll(image.getGraphics());

    // Render the component and ignoring its sub components
    c.paint(image.getGraphics());
// Save the image out to file
ImageIO.write(image, format, new File(filename));

}

but i didn’t find a way for drawing only a region of this component.
Any idea ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T08:18:13+00:00Added an answer on May 18, 2026 at 8:18 am

    You need to translate like this:

    BufferedImage image = new BufferedImage(100, 100, BufferedImage.TYPE_INT_ARGB);
    
    Graphics g = image.getGraphics();
    g.translate(-100, -100);
    
    c.paintComponent(g);
    
    g.dispose();
    

    Full example with output:

    Resulting image

    public static void main(String args[]) throws Exception {
    
        JFrame frame = new JFrame("Test");
        frame.add(new JTable(new DefaultTableModel() {
            @Override
            public int getColumnCount() {
                return 10;
            }
            @Override
            public int getRowCount() {
                return 10;
            }
            @Override
            public Object getValueAt(int row, int column) {
                return row + " " + column;
            }
        }));
    
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setSize(400, 300);
        frame.setVisible(true);
    
        BufferedImage image = new BufferedImage(100, 100, BufferedImage.TYPE_INT_ARGB);
        Graphics g = image.getGraphics();
        g.translate(-100, -100);
    
        frame.paintComponents(g);
    
        g.dispose();
    
        ImageIO.write(image, "png", new File("frame.png"));
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my app I need to draw a widget contents onto Bitmap. The code(pseudo)
I need to use a custom NSView subclass to draw some content, but it
I want to draw DirectX content so that it appears to be floating over
I want to draw a image like below. http://enterprise-now.com/wp-content/uploads/2011/02/ValueChain.png My database has followed a
I need to draw a rectange,circle and line and then animate them(press left ->
I need to draw vertical and horizontal rectangle / bands (like in Gantt charts)
I need to draw simple alpha maps in xna which depends on current game
I need to draw a chart to show the evolution of data in real
I need to draw a lot of lines. I'm using UIBezierPath for drawing lines
I need to draw 2D overlay over OpenGL scene. OpenGL is used for 2D

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.