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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T18:26:34+00:00 2026-05-31T18:26:34+00:00

I only need a table to show 3 rows which get top 3 selling

  • 0

I only need a table to show 3 rows which get top 3 selling products from DB. The table is ready, but the there’s a huge portion of table which is practically empty, except for 3 rows. How can I set height of this scrollpane to match the height of 3 rows?

SOLUTION:

table.setPreferredScrollableViewportSize(table.getPreferredSize());
  • 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-31T18:26:35+00:00Added an answer on May 31, 2026 at 6:26 pm

    It’s a quirk of the JTable’s Scrollable implementation: it sets an arbitrary fixed prefScrollable size.

    You null it to make the scrollPane to fall back to using the table’s preferredSize:

    table.setPreferredScrollableViewportSize(null);

    Edit

    outch, @vedran is correct, that’s not always working in a core table with core layoutManagers (it was a nice hack in another question 🙂 sorry for the confusion. Copying his comment here:

    table.setPreferredScrollableViewportSize(table.getPreferredSize());
    

    is a viable option, though all the usual bewares about hard-coding sizes apply here as well.

    A well-behaved JTable would implement a more reasonable getPreferredScrollableViewportSize, f.i calculating it in terms of content. JXTable (which is the best-behaved table, biased me :-), you could set the pref in terms of visible rows, just as in a list:

    xtable.setVisualRowCount(3); 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table with 11 columns, but I need to get only 2
I just need to show my plain html table in which it shows only
I need to only find the cells in the table which contain   using
I need to select and act on a table element with JQuery, but only
I need to show more than one result from each field in a table.
I have a table var with some rows but only one column of type
Every night I need to trim back a table to only contain the latest
The DataReader is more efficient than a DataTable if you only need to show
I use huge data files, sometimes I only need to know the number of
Imagine the following: you read in a string with scanf() but you only need

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.