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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T22:47:23+00:00 2026-06-14T22:47:23+00:00

I have this code, where Canvas is a class I made that extends JPanel

  • 0

I have this code, where Canvas is a class I made that extends JPanel it holds an image. But when I use it, it places the canvas not on top of the JScrollPane, but behind it. Why is it doing that?

Here is how the ScrollPanel is created:

imagePane.setBackground(new java.awt.Color(153, 153, 153));
imagePane.setBorder(null);
jSplitPane2.setRightComponent(imagePane);

Here is the placement of my Panel within the ScrollPanel

Canvas canvas = new Canvas();
canvas.setVisible(true);
canvas.setImage(file);
imagePane.setLayout(new GridBagLayout());
canvas.setSizeFromLoaded();
imagePane.add(canvas);
imagePane.repaint();

The canvas class doesn’t do anything with placement of the Panel, all it does is build and modify it. I did have a JPanel there and it worked, but once I switched it out with a JScrollPanel it started placing the canvas behind it.

  • 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-14T22:47:24+00:00Added an answer on June 14, 2026 at 10:47 pm

    The problem I came up with to fix this is to use this:
    imagePane.getViewport().add(canvas);

    Instead of this:
    imagePane.add(canvas);

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

Sidebar

Related Questions

i have this code to show gif image with Movie. public class GIFView extends
I have this code here that creates a Tkinter Canvas widget, then embeds an
I have this code that should move an object down but it stands still
I have a code where I draw image: class Panel extends View { public
I have this code for changing the image of a button: - (void)mouseEntered:(NSEvent *)event
I have this code inside my class MainWindow : public MainWindow() { super(Shouldn't be
Hey I have made this GUI, that shows matplotlib plots in a tkinter interface
I have no idea why this code does not loop as it should. My
I have this source code: var Game = function() { var canvas = document.getElementById('world');
I have to use a canvas class to add frame and multiple images on

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.