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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T19:16:10+00:00 2026-05-13T19:16:10+00:00

I hava a table in a scrollPane . There are 6 columns in my

  • 0

I hava a table in a scrollPane. There are 6 columns in my table. I want the last 2 columns to be wider than other columns. But after I set the size of the columns, the vertical scroll bar disappeared. If I comment out the code for resetting the columns width, everything goes back to normal. Could anyone tell me what’s the problem of this? Thanks a lot!!

I copied several related dimentions blow:

table.setPreferredScrollableViewportSize(new Dimension(900, 500));
feedback = new JScrollPane(table);
feedback.setMinimumSize(new Dimension(900, 400));

the code to resize the columns:

TableColumn column = null;
for (int i = 0; i < 6; i++) {
    column = table.getColumnModel().getColumn(i);
    if (i == 4) {
        column.setPreferredWidth(250); //third column is bigger
    } else { 
        if (i==5) {
           column.setPreferredWidth(250);
        }
        else {
            column.setPreferredWidth(100);
        } 
    }
} 
  • 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-13T19:16:10+00:00Added an answer on May 13, 2026 at 7:16 pm

    I am unable to reproduce the problem you describe. It may a problem with your layout, or it may require Setting the Scroll Bar Policy.

    import javax.swing.*;
    import javax.swing.table.*;
    
    public class TablePanel extends JPanel {
    
        public static void main(String[] args) {
            SwingUtilities.invokeLater(new Runnable() {
                @Override
                public void run() {
                    JFrame f = new JFrame("JTable");
                    f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
                    f.add(new TablePanel());
                    f.pack();
                    f.setVisible(true);
                }
            });
        }
    
        public TablePanel() {
            TableModel dataModel = new MyTableModel();
            JTable table = new JTable(dataModel);
            table.setAutoCreateRowSorter(true);
            table.getColumnModel().getColumn(0).setPreferredWidth(100);
            table.getColumnModel().getColumn(1).setPreferredWidth(150);
            table.getColumnModel().getColumn(2).setPreferredWidth(200);
            JScrollPane jsp = new JScrollPane(table);
            this.add(jsp);
        }
    
        private static class MyTableModel extends AbstractTableModel {
    
            @Override
            public int getRowCount() {
                return 30;
            }
    
            @Override
            public int getColumnCount() {
                return 3;
            }
    
            @Override
            public Object getValueAt(int row, int col) {
                return Math.pow(row, col + 1);
            }
    
            @Override
            public Class<?> getColumnClass(int col) {
                return getValueAt(0, col).getClass();
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I hava a JFrame with multiple JPanels of similar width aligned one below other.
I hava very large table with 1373228 rows. I need to copy the result
i hava a placed a select statement inside a table cell. The ui was
I hava set up AJAX script that when you click the button it calls
I hava a UINavigationController. The first level is a UITableViewController, the second level just
I have a regression model in which the dependent variable is continuous but ninety
How can i get the nth row position from table without using limit ?
i am using diaply tags library for displaying my tables.But i cant use the
How can i create partialy colored cell in reporting services table or matrix? For
I hav a model called User ( table: users ). I hav populated 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.