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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T22:27:56+00:00 2026-06-10T22:27:56+00:00

I am trying to resize the widths of the columns in a JTable. I

  • 0

I am trying to resize the widths of the columns in a JTable.
I would need to resize them when the program is running to see the full column header names.
I want to resize table of database showing in swing frame.

I have tried

table.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS)

But I didn’t get the desired output because when I use this I have a horizontal scrollbar to scroll to the columns that are off screen. But I want the size of the whole table to become approximately equal to the size of frame.

How can I make the columns as wide as they need to be to display all the text?

  • 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-10T22:27:58+00:00Added an answer on June 10, 2026 at 10:27 pm

    But I want the size of the whole table to become approximately equal to the size of frame.

    JTable table = ...;
    JFrame frame = ...;
    JPanel contentPane = new JPanel( new BorderLayout() );
    contentPane.add( new JScrollPane( table ), BorderLayout.CENTER );
    frame.setContentPane( contentPane );
    

    How can I make the columns as wide as they need to be to display all the text?

    Unfortunately, the maximum width of the JTable will be limited to the size of the JFrame, and there is no mechanism to push from your JTable the desired width to the JFrame when your JTable is contained in a JScrollPane.

    What you could do is try to give your JScrollPane the correct width. I haven’t tried this, but I suspect that giving your scrollpane the same width as the preferred width of your table (when autoresize is on) should solve this (+ perhaps some extra width for the vertical scrollbar). Note however that this will only work if you allow your JFrame in which the JScrollPane is contained to grow in width as well.

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

Sidebar

Related Questions

When i'm trying to resize datagridview columns the resize cursor appears only when i
I'm trying to resize one image to 5 different sizes (and then upload them
I am having serious problems trying to resize columns in a DataGrid. I've been
I am trying to resize evenly all the columns of a ListView and it
I'm trying to build a two-column layout where the width of the columns can
Im trying to create a 3 column DIV that allows me to resize the
I'm trying to create flowing content using CSS columns, but I'm running into the
I'm trying to resize a fullsize image poster into three smaller variants of the
I'm trying to resize an array of a certain class passed as an argument,
I'm trying to resize an image in Silverlight 3 that has been submitted by

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.