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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T05:24:11+00:00 2026-06-15T05:24:11+00:00

I have this code, and it makes a JPanel and adds it to a

  • 0

I have this code, and it makes a JPanel and adds it to a JScrollPanel. It works fine, but when I try to add a second JPanel it removes the first one and adds the second one. I would like to be able to place JPanels on top of JPanels, how can I do that?

// Location of an image:
String file = wfc.getSelectedFile().getPath();

// Creates images from different types:
ImageHandler image = new ImageHandler();
BufferedImage imageData = image.imageData(file);

// Extends JPanel, Layer is a JPanel
Layer layer = new Layer(image.width(), image.height());
layer.setImage(imageData);
layer.setSizeFromLoaded();
// A list of all the JPanels added
Layers.set(Layers.layers.size(), layer);

// Adds a JPanel to the JScrollPanel
imagePane.getViewport().add(layer, BorderLayout.CENTER);

Here is the full method, it opens a file browser, then when the image is selected it runs the above code

private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {
    WebFileChooser wfc = null;
    if(wfc == null){
        wfc = new WebFileChooser(this, "Open an Image");
        wfc.setSelectionMode(SelectionMode.SINGLE_SELECTION);
        wfc.setAvailableFilter(GlobalConstants.IMAGES_AND_FOLDERS_FILTER);
        wfc.setChooseFilter(GlobalConstants.IMAGES_FILTER);
        wfc.setCurrentDirectory("/Users");
    }
    wfc.setVisible(true);

    if(wfc.getResult() == StyleConstants.OK_OPTION){
        String file = wfc.getSelectedFile().getPath();

        ImageHandler image = new ImageHandler();
        BufferedImage imageData = image.imageData(file);

        Layer layer = new Layer(image.width(), image.height());
        layer.setImage(imageData);
        layer.setSizeFromLoaded();
        Layers.set(Layers.layers.size(), layer);

        imagePane.getViewport().add(layer, BorderLayout.CENTER);
    }
}
  • 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-15T05:24:12+00:00Added an answer on June 15, 2026 at 5:24 am

    I used Zove Games suggestion and placed it within a JLayerdPanel, and it works perfectly!

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

Sidebar

Related Questions

So i have this code which makes a box, but want to make the
I have this code that makes a string and then echos the loop out
I have this code, but i cant make it work: images = Image.find_by_sql('PREPARE stmt
I have this code that I want to make point-free; (\k t -> chr
I have this code and I need to make this work: if ($handle =
I have this code App.Model('users').find(function (err, users) { users.forEach(function(user) { console.log(user.username); }); }); //make
I have this unsafe code that I need to make safe so it can
I have written this code in javascript however I have to make it work
How do you make this code work? Just have pyglet installed and change fireball.png
I have this code <div id=main style=background:#aaaaaa;float:left;height:160px;margin:5px;position:relative;display:block;width:630px;> <div id=1 class=item style=background:#ffaacc;float:left;width:200px;height:150px;margin:5px;position:absolute;left:0px;top:0px;> </div> <div id=2

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.