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

  • Home
  • SEARCH
  • 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 6747473
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T12:26:46+00:00 2026-05-26T12:26:46+00:00

INTRO: I created a java application using JFrame. I have a JMenuBar at the

  • 0

INTRO:
I created a java application using JFrame. I have a JMenuBar at the top and under that I’d like to display rows of text.

PURPOSE:
When I have 50 rows and only 20 are displayable at once, I’d like to be able to scroll down and back up again.

PROBLEM:
Of course, my theory doesn’t wanna work as it should. My problem is that I don’t know how to add a vertical scroll properly.

QUESTION:
How should I change this code to reach my goal?

public void display(){

    Container content = this.window.getContentPane();
    content.setLayout(new BorderLayout());
    Border border = LineBorder.createGrayLineBorder();

    //this is just a sample 
    for(int i = 0;i<50;i++){
        JLabel lab = new JLabel("lonyaladek");
        lab.setSize(570, 20);
        lab.setBorder(border);
        lab.setLocation(10, 20+(i*25));
        content.add(lab);
    }

    //scroll
    JScrollBar sb = new JScrollBar(JScrollBar.VERTICAL, 0, 0, 0, 0);
    content.add(sb);
}
  • 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-26T12:26:47+00:00Added an answer on May 26, 2026 at 12:26 pm

    First you need to start with a layout manager that allows you to add multiple components to the container. Maybe a GridLayout is the best place to start.

    Then you add this container to the scrollPane and then you add the scrollpane to the window.

    So the basic code would be:

    JPanel panel = new JPanel( new GridLayout(0, 1) );
    panel.add(...);
    panel.add(...);
    JScrollPane scrollPane = new JScrollPane( panel );
    window.add(scrollPane, BorderLayout.CENTER);
    

    I suggest you read the section from the Swing tutorial on How to Use Scroll Panes for more info.

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

Sidebar

Related Questions

I have created a java web application using spring. I want the users of
I have created a java application and packed it into a jar file on
I have troubles using the java ServiceLoader in a NetBeans module application. Here is
I have written a standalone Java application that I've packaged into a jar file
I've created a simple Java application that each second for for 10 seconds consecutive
I've created a form that stores free text fields into a MySQL database. All
I have a java application which has a GUI in both English and French,
I have a spring MVC application using JSP as my view technologies with Jquery
I have a relatively small Java library that implements a few dozen beans (no
I am developing a Java web services application that is (mostly) to be used

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.