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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T21:01:23+00:00 2026-06-05T21:01:23+00:00

I have below snippet of code in which TestClass is extending jPanel which is

  • 0

I have below snippet of code in which TestClass is extending jPanel which is using SpringLayout, in which I’m not able to add vertical scrollbar.

Could you please help me guys?



        public class TestClass extends JPanel {

            private SpringLayout layout;
            private Spring s, sprWest;
            private JComboBox comboDevice = new JComboBox();
            private JComboBox comboCommand = new JComboBox();
            private JLabel lblDevice = new JLabel("Select the Device:");
            private JLabel lblCommand = new JLabel("Select Command:");
            private JButton btnCommand = new JButton("Save");

            public TestClass () {
                layout = new SpringLayout();
                s = Spring.constant(0, 60, 60);
                setLayout(layout);
            }

            public void populateFields(){
                add(lblCommand);
                add(comboCommand);


                sprLblEast = Spring.sum(s, Spring.max(layout.getConstraints(lblCommand).getWidth(), layout.getConstraints(lblDevice).getWidth()));
                Spring strut = Spring.constant(10);

                layout.putConstraint(SpringLayout.NORTH, lblCommand, strut, SpringLayout.SOUTH, comboDevice);
                layout.putConstraint(SpringLayout.NORTH, comboCommand, strut, SpringLayout.SOUTH, comboDevice);
                layout.putConstraint(SpringLayout.EAST, lblCommand, sprLblEast, SpringLayout.WEST, this);
                layout.putConstraint(SpringLayout.WEST, comboCommand, Spring.sum(s, layout.getConstraints(lblCommand).getWidth()), SpringLayout.WEST, lblCommand);
                layout.putConstraint(SpringLayout.EAST, this, sprLblEast, SpringLayout.WEST, comboCommand);

                List cmdList = getCommandList();
                for (int index = 0; index < cmdList.size(); index++) {
                    comboCommand.addItem(cmdName);
                }
                validate();
                repaint();
            }
    }


  • 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-05T21:01:24+00:00Added an answer on June 5, 2026 at 9:01 pm

    I would sugest use of ScrollPane

    ScrollPane mainWindow = new ScrollPane(ScrollPane.SCROLLBARS_AS_NEEDED);
    mainWindow.add(this);

    but You would have to use another object than Your TestClass as view, here it would be mainWindow.

    You could use also JScrollPane from Swing: tutorial for JScrollPane

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

Sidebar

Related Questions

I have the code snippet below in C++ which basically calculates the pi using
I have created a tab-pane using HAML as shown in my code snippet below
I have been pulling my hair above below snippet of code - which is
Below is the code snippet with comments which describes the problem statement. We have
I have a sample code snippet below which works just fine (I trimmed the
I have found a code snippet as given below which is used to disable
I have below code snippet SimpleDateFormat dateFormat = new SimpleDateFormat( yyyy-MM-dd hh:mm:ss.SSS); String processedContentDate=2012-04-10
I have a code snippet as below <CheckBox Name=cb Margin=1,2,1,0 IsChecked={Binding Path=IsManager} IsEnabled=True/> Consider
I have this snippet of code below. I want to pass the value of
Below is the snippet of my code. I have a JTable. I have extended

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.