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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T11:03:27+00:00 2026-06-14T11:03:27+00:00

I have a JTable in a JScrollPane. I want the minimum width to be

  • 0

I have a JTable in a JScrollPane. I want the minimum width to be around 600 as its a wide table. I tried setting the minimum size on the table, the scroll pane, and the panel its self. The size doesn’t change at all, what am I missing? Its hard to google this because all that comes up is how to set the width of the columns.

enter image description here

Here is the code:

class SearchResults extends JPanel {

/**
 * Create the panel.
 */
public SearchResults() {
    setMinimumSize(new Dimension(640, 480));
    String[][] data= new String[][] {
            {null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, "VIEW BUTTON"},
            {null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, "VIEW BUTTON"}};
    String[] col = new String[] {
            "Last Name", "First Name", "Middle Initial", "Phone Number", "Email", "Project Title", "Project Description", "Amount", "Date Approved", "Date Completed", "College", "Faculty Mentor Name", "Co Grantee", "Major", "Travel Required", "Travel Purpose", "Travel Cost", "Travel Start Date", "Travel End Date", "View"};

      JTable table = new JTable(data,col);
      table.setMinimumSize(new Dimension(600,200));
      JTableHeader header = table.getTableHeader();
      JScrollPane pane = new JScrollPane(table);
      pane.setMinimumSize(new Dimension(600, 23));
      table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
      add(pane);
}

}

And here is where I add it to the JFrame:

public class Test extends JFrame
{

    public static void main(String[] args)
    {
        Test test = new Test();
        test.run();
    }

    public Test()
    {
        super("JAVA TEST!");
    }

    private void run()
    {
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        SearchResults resultsPanel = new SearchResults();
        resultsPanel.setMinimumSize(new Dimension(600,200));
        add(resultsPanel);
        setSize(800,600);
        setVisible(true);
    }
}
  • 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-14T11:03:28+00:00Added an answer on June 14, 2026 at 11:03 am

    There are several problems:

    • (as already mentioned in my comment) the FlowLayout of the inner panel always sizes its children to their respective prefSize
    • a table’s min/pref/max width is calculated from the sum of the respective column sizes
    • a table is-a Scrollable and as such publishes its preferredScrollableViewportSize (which is the size a surrounding JScrollPane uses to calculates its own prefSize)
    • the implementation of prefScrollable is … lacking (to put it mildly) in that its hard-coded to something like 400 x 450 (or similar)

    Consequestly, there are several screws to tweak (after removing all setXXSize calls 🙂 )

    • make the panel use a BorderLayout: the scrollPane will fill the complete area if the frame is resized.
    • extend the JTable to return something reasonable for prefScrollableViewportSize (f.i. in terms of the pref number of visible columns/rows)

    In code (and using JXTable of the SwingX project because it already has api for the second 🙂 )

    String[][] data= new String[][] {
            {null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, "VIEW BUTTON"},
            {null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, "VIEW BUTTON"}};
    String[] col = new String[] {
            "Last Name", "First Name", "Middle Initial", "Phone Number", 
            "Email", "Project Title", "Project Description", "Amount", 
            "Date Approved", "Date Completed", "College", "Faculty Mentor Name", 
            "Co Grantee", "Major", "Travel Required", "Travel Purpose", 
            "Travel Cost", "Travel Start Date", "Travel End Date", "View"};
    
     JXTable table = new JXTable(data,col);
     table.setVisibleColumnCount(10);
     table.setHorizontalScrollEnabled(true);
     JScrollPane pane = new JScrollPane(table);
     JComponent comp = new JPanel(new BorderLayout());
     comp.add(pane);
    

    Edit

    To solve the 80% requirement (and a little teaser for MigLayout 🙂 )

    // 80% with a minimum of 600 logical pixel:
    MigLayout layout = new MigLayout("wrap 2, debug",
            "[600:pref, fill, grow][20%]");
    JComponent comp = new JPanel(layout);
    comp.add(pane, "spany");
    comp.add(new JLabel("just something"));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a JTable that uses JTextArea as its TableCellRenderer, so that table cells
I have a problem with JTable / JScrollPane . My data table is not
I have a JTable inside a JScrollPane. After calling my function which should populate
I have a JTable inside a JScrollPane. In one of the columns in the
I have a JTable inside of a JScrollPane . I am creating a custom
I have a JTable which I want to have left-click and right-click JPopupMenu on
I have a JTable that I want to use to display some data (a
I have a JScrollPane with a JTable in it. In the JTable I have
I have this structure: <JFrame> <JPanel backgroundcolor = pink> <JScrollPane> <JTable>!!!Data here !!!</JTable> </JScrollPane>
I have added jTable inside the jScrollPane as : public Scenario_One() { initComponents(); jScrollPane1.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);

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.