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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T06:37:21+00:00 2026-05-26T06:37:21+00:00

I’m having an issue in my application. I wish to dynamically create several tabbed

  • 0

I’m having an issue in my application. I wish to dynamically create several “tabbed” scrollpanes that hold a semi-large amount of objects called “ImageLabels”, which are just labels with (you guessed it) images on them.

I made most of my gui in Netbeans, as it is semi-complicated and I’m too nooby to do it myself.

My problem is this: When adding my scrollpane objects (that contain a JPanel with a GridLayout), and after I attempt to add my imagelabels to the JPanel with the layout (my constructor is set to “new GridLayout(0, 5, 5, 5);” which is unlimited rows, 5 columns, with 5 pxls of space.) nothing shows up, nor does the scrollpanel go into “scroll” mode.

I am completely at a loss and have been trying all day with different layouts. Here’s some code I have…

Constructor of the ImageLabel object..

addMouseListener(this);
setVisible(true);
setPreferredSize(new Dimension(32, 32));

How I set up my tileHolderPanel JPanel (the panel holding the ImageLabels)

myLayout = new GridLayout(0, 5, 5, 5);
tileHolderPanel.setLayout(myLayout);

and after constructing all of the ImageLabels I wish to add to each panel, I simply do

tileHolderPanel.add(label);

If it matters, my TileHolderPanel is inside of a scrollpane which is inside a JPanel,and they have the default GroupLayouts which Netbeans generates.

Thank you,
-Luke

  • 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-26T06:37:22+00:00Added an answer on May 26, 2026 at 6:37 am

    Here’s a working example with which to compare your code.

    enter image description here

    import java.awt.Color;
    import java.awt.Dimension;
    import java.awt.EventQueue;
    import java.awt.GridLayout;
    import javax.swing.GroupLayout;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    import javax.swing.JScrollPane;
    
    /** @see http://stackoverflow.com/questions/7801870 */
    public class ScrollGroup extends JPanel {
    
        private static final int N = 8;
        private static final int NN = N * N;
        private static final int GAP = 5;
        private static final int SIZE = 32;
    
        public ScrollGroup() {
            this.setLayout(new GridLayout(N, N, GAP, GAP));
            for (int i = 0; i < NN; i++) {
                JLabel label = new JLabel();
                label.setOpaque(true);
                label.setBackground(Color.getHSBColor((float) i / NN, 1, 1));
                label.setPreferredSize(new Dimension(SIZE, SIZE));
                this.add(label);
            }
        }
    
        private void display() {
            JFrame f = new JFrame("ScrollGroup");
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            JScrollPane sp = new JScrollPane(this);
            GroupLayout layout = new GroupLayout(f.getContentPane());
            f.setLayout(layout);
            layout.setAutoCreateGaps(true);
            layout.setAutoCreateContainerGaps(true);
            layout.setHorizontalGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup().addComponent(sp)));
            layout.setVerticalGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup().addComponent(sp)));
            f.pack();
            f.setSize(N * SIZE, N * SIZE);
            f.setLocationRelativeTo(null);
            f.setVisible(true);
        }
    
        public static void main(String[] args) {
            EventQueue.invokeLater(new Runnable() {
    
                @Override
                public void run() {
                    new ScrollGroup().display();
                }
            });
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to create an if statement in PHP that prevents a single post
That's pretty much it. I'm using Nokogiri to scrape a web page what has
Basically, what I'm trying to create is a page of div tags, each has
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
We're building an app, our first using Rails 3, and we're having to build
I need a function that will clean a strings' special characters. I do NOT
I'm having trouble keeping the paragraph square between the quote marks. In firefox the

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.