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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T21:46:42+00:00 2026-06-09T21:46:42+00:00

How to make that BMP will fill the JPanel? import java.awt.Dimension; import java.awt.Graphics; import

  • 0

How to make that BMP will fill the JPanel?

import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;

public class BMPPanel extends JPanel {


    String sciezka;
    Image image;
    int skala;
    int rozdzielczosc;
    Dimension d;
    public static int NORMALNA = 0, MALA = 1;

    public BMPPanel(String sciezka, int skala, int rozdzielczosc) {
        this.sciezka = sciezka;
        this.skala = skala;
        this.rozdzielczosc  = rozdzielczosc;
        super.setMaximumSize(d);
        this.d = new Dimension(400,400);
        this.go();
    }
    public BMPPanel(String sciezka, int skala) {
        this(sciezka,skala,200);
    }


    public void go() {
        try {
            File input = new File(sciezka);
            image = ImageIO.read(input);
        } catch (IOException e) {
            e.printStackTrace();
        }



        setPreferredSize(new Dimension(image.getWidth(null),
                image.getHeight(null)));
    }

    @Override
    public void paintComponent(Graphics g) {
        super.paintComponents(g);
        Graphics2D g2d = (Graphics2D) g;
        g2d.drawImage(image, 0, 0, this);
    }

    @Override 
    public void setMaximumSize(Dimension d){

    }



}
  • 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-06-09T21:46:44+00:00Added an answer on June 9, 2026 at 9:46 pm

    The first question you need to answer, is do you wish to maintain the aspect ratio of the BMP?

    If you don’t then it’s as simple as

    Image scaled = image.getScaledInstance(getWidth() - 1, getHeight() - 1, Image.SCALE_SMOOTH);
    

    If not, then you need to ask your self. Do I want to “fill” or “fit” the image. Filling will allow the image to overflow the panel, but will completely fill it, fit will make sure the entire image will fit into the panel, but may leave gaps.

    Have a read of this answer which is in response to a similar question

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

Sidebar

Related Questions

I didn't make the image into binary form, but want to get that image
I need to make application that will catch EVERY SINGLE SMS that phone receives,
I'm creating a class called ImageLoader that will be used to load various image
Short question: I'm trying to make that in a given page (uses tabs) back
I have a WordPress blog and I'm trying to make that when a user
Ok, so I'll try to make that question a little more simple. The core
I have a ColorChooser panel, how can I make that appear when I click
I apologize if the title sounds abstruse, let me make that simple with an
Suppose I have an element called #container-main . How do I make that display:none
First of all, I'm using Windows, just to make that clear. I am using

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.