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 532259
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T09:23:11+00:00 2026-05-13T09:23:11+00:00

I am using a custom subclass of JPanel to offer me more control over

  • 0

I am using a custom subclass of JPanel to offer me more control over the display of some images. The code to it is below.

However, in Netbeans, in design mode, I would like to be able to see the image that I am working with, instead of simply looking at the outline of the object.

There is an image attribute, but the only way I can currently set the image is to inject custom code into the image attribute.
However, I am unsure what code I need to include in order to view the image, or if there is a simpler way of doing it.

import javax.swing.*;
import java.awt.*;

public class ImagePanel extends JPanel {

  private Image img;

  public void setImage(String img) {
    this.img = new ImageIcon(img).getImage();//setImage(new ImageIcon(img).getImage());
  }

  public void setImage(Image img) {
    int width = this.getWidth();
    int height = (int) (((double) img.getHeight(null) / img.getWidth(null)) * width);
    this.img = img.getScaledInstance(width, height, Image.SCALE_SMOOTH);
  }

  public void paintComponent(Graphics g) {
    g.drawImage(img, 0, 0, this);
  }
}

alt text http://img691.imageshack.us/img691/2128/tempscreen.png

  • 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-13T09:23:11+00:00Added an answer on May 13, 2026 at 9:23 am

    Change:

    public void setImage(String img) {
    

    To:

    public void setImageName( String img ) {
    

    Rebuild, and set the ImageName property in the designer. In the original code, the designer thinks that the bean property Image is of type java.awt.Image, rather than String. It does not know how to specify a java.awt.Image at design time to your bean. However it can easily pass Strings to your bean, you just need to give it an unambiguous String bean property (ImageName).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using an NSDocumentController subclass to do some custom stuff when I create
In an iPad app, I'm using a custom subclass of UIView with UIViewController. Here's
When using drawRect for a custom UIButton subclass, it never seems to get called
I'm using custom WordPress categories for some probably unintended functions, I will admit (things
I'm using a custom UIGestureRecognizer subclass to track gestures on my InfoView class. The
I am using a custom subclass of UIImageView, but I can't figure out why
I am using navigation with a custom UIView subclass that becomes my titleView. I
I'm using a table view that uses a custom UITableViewCell subclass, NoteCell . The
I've created a custom subclass of NSCell with an NSImageCell, some NSTextFieldCells, and an
Using Google App Engine (python SDK), I created a custom JSONProperty() as a subclass

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.