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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T12:15:52+00:00 2026-06-04T12:15:52+00:00

Okay, I have a Jpanel which is shown as white in the below image

  • 0

Okay, I have a Jpanel which is shown as white in the below image using an overlay layout. It holds a ScrollPane holding an image (“No Image Available”) and a JButton (“Comment”).

enter image description here

I want to position this button in the bottom right hand corner of the JPanel. I have tried multiple layout approaches and I cant seem to get it to work. At most the button moves about 3/4 of the way South-East and I have no idea why.

Any help is greatly appreciated..

  • 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-04T12:15:54+00:00Added an answer on June 4, 2026 at 12:15 pm

    There are a lot of possible solutions using different layout managers. I don’t know the OverlayLayout, but I like WindowBuilder Pro (free): https://developers.google.com/java-dev-tools/wbpro/ for help with Swing design.

    Using it, I wrote a SpringLayout implementation of your question (SpringLayout seems like a pain to deal with without a GUI-builder).

    JPanel panel = new JPanel();
    SpringLayout sl_panel = new SpringLayout();
    panel.setLayout(sl_panel);
    
    JButton button = new JButton("Comments");
    sl_panel.putConstraint(SpringLayout.SOUTH, button, 0, SpringLayout.SOUTH, panel);
    sl_panel.putConstraint(SpringLayout.EAST, button, 0, SpringLayout.EAST, panel);
    panel.add(button);
    
    JScrollPane scrollPane = new JScrollPane();
    sl_panel.putConstraint(SpringLayout.NORTH, scrollPane, 5, SpringLayout.NORTH, panel);
    sl_panel.putConstraint(SpringLayout.WEST, scrollPane, 3, SpringLayout.WEST, panel);
    sl_panel.putConstraint(SpringLayout.SOUTH, scrollPane, 3, SpringLayout.SOUTH, panel);
    sl_panel.putConstraint(SpringLayout.EAST, scrollPane, 3, SpringLayout.EAST, panel);
    panel.add(scrollPane);
    
    JLabel lblNewLabel = new JLabel();
    lblNewLabel.setIcon(new ImageIcon(foo.class.getResource("sSdA3.png")));
    scrollPane.setViewportView(lblNewLabel);
    

    Here’s a picture of the code running:

    enter image description here

    You can see the button (mine, not the picture of yours…) is floating above the scroll-pane in the bottom. We could adjust the margins above so the button wasn’t floating on top of the scroll-bars, but this is just to show you where it is on the z-axis.

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

Sidebar

Related Questions

Okay I have a small app for uploading an image (using phonegap, Jquery). I
Okay I have a series of objects based on a base class which are
okay i have found the way to run a video in a image.... the
Okay so I have a web view that holds the chat bar div from
I have a heredoc form (shown below) inside addToDb.php. The form posts back to
Okay I have the below code performing something I don't want it to do.
Okay I have a project that is using the android-rss library (org.mcsoxford.rss). I created
Okay I have a webView which loads a web page. The web view fits
Okay I have this RewriteRule which is supposed to redirect any request for the
Okay so I have the following Code which appends a string to another in

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.