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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T01:06:45+00:00 2026-06-13T01:06:45+00:00

I have added jTable inside the jScrollPane as : public Scenario_One() { initComponents(); jScrollPane1.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);

  • 0

I have added jTable inside the jScrollPane as :

    public Scenario_One() {
      initComponents();
      jScrollPane1.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
      jScrollPane1.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
    }

    private void initComponents() {
       .
       .
       jScrollPane1.setViewportView(jTable1);
       .
       .
    }

The text to displayed in one single row is too large so I had to use horizontal scroll bars. But even after setting the policy to as needed I do not see the horizontal scroll bars. What could be the reason for this ?

  • 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-13T01:06:46+00:00Added an answer on June 13, 2026 at 1:06 am

    Try something like this…

    enter image description here

    public class TestTableColumns {
    
        public static void main(String[] args) {
            new TestTableColumns();
        }
    
        public TestTableColumns() {
            EventQueue.invokeLater(new Runnable() {
                @Override
                public void run() {
                    try {
                        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
                    } catch (ClassNotFoundException ex) {
                    } catch (InstantiationException ex) {
                    } catch (IllegalAccessException ex) {
                    } catch (UnsupportedLookAndFeelException ex) {
                    }
    
                    DefaultTableModel model =new DefaultTableModel(
                                    new Object[][] {
                                        {"1", "2"},
                                        {"11", "21"},
                                        {"12", "22"},
                                        {"13", "23"},
                                        {"14", "24"},
                                        {"15", "25"},
                                        {"16", "26"},
                                        {"17", "27"},
                                        {"18", "28"}}, 
                                    new Object[] {
                                        "Small", "Big"});
    
                    JTable table = new JTable(model);
                    table.setShowHorizontalLines(true);
                    table.setShowVerticalLines(true);
                    table.setShowGrid(true);
                    table.setGridColor(Color.DARK_GRAY);
                    table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
                    table.getColumn("Small").setPreferredWidth(100);
                    table.getColumn("Small").setWidth(12);
                    table.getColumn("Big").setPreferredWidth(400);
                    table.getColumn("Big").setWidth(100);
    
                    JFrame frame = new JFrame();
                    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                    frame.setLayout(new BorderLayout());
                    frame.add(new JScrollPane(table));
                    frame.pack();
                    frame.setLocationRelativeTo(null);
                    frame.setVisible(true);
                }            
            });
        }    
    }
    

    The width of the view port is dictated by the width of the component it contains. For a JTable, that is determined by the size of the columns and the auto size policy

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

Sidebar

Related Questions

I have a JTable with custom TableCellRenderer. public class DateCellRenderer extends DefaultTableCellRenderer { private
I have a JTable that is within a JScrollPane. Rows are added to the
The problem I have is that when more rows are added to JTable (jtbls)
I have added a navigation controller inside a viewcontroller thats inside another navigation controller...
I have a JScrollPane with a JTable in it. In the JTable I have
Have added activityviewcontroller to the main controller -(void)ActionSheet2:(id)sender { UIActivityViewController *activityViewController = [[UIActivityViewController alloc]
I have added a new GIT repo (private github repo) to Eclipse EGit repo
I have: a JTable , embedded in a JScrollPane , containing a list of
I have buttons in the JTable. I have added ActionListener to these butons, but
I have added multiple JProgressBar to TableColumn of JTable . I am updating all

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.