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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T21:36:47+00:00 2026-06-08T21:36:47+00:00

The following component is later added to the JFrame, but it does does not

  • 0

The following component is later added to the JFrame, but it does does not stretch the JTable as I stretch the frame to fill up the scrollPane:

public class TableView extends JPanel {

  public TableView(TableModel model) {

    JTable table = new JTable(model) {
        @Override
        public Component prepareRenderer(TableCellRenderer renderer, int row, int column) {
            Component c = super.prepareRenderer(renderer, row, column);
            TradeTableModel model = (TradeTableModel) getModel();
            if ((Boolean) model.getValueAt(row, model.findColumn("Select"))) {
                Side s = (Side) model.getValueAt(row, model.findColumn("Side"));
                if (s == Side.BUY)
                    c.setBackground(Color.BLUE);
                else
                    c.setBackground(Color.red);
            } else {
                c.setBackground(Color.white);
            }
            return c;
        }
    };
    table.setPreferredScrollableViewportSize(new Dimension(500, 70));
    table.setFillsViewportHeight(true);
    JScrollPane scrollPane = new JScrollPane(table);
    add(scrollPane);
  }

}

I added:

super(new GridLayout(1, 0));

and it fixed the problem. But why is the layout required? Isn’t there simply a default layout that would be instantiated in the case of calling super()? I simply want to know what stops the table to stretch to the size of the scroll pane in the first version

Edit: fixed only code format, but must add some text to submit :/

  • 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-08T21:36:48+00:00Added an answer on June 8, 2026 at 9:36 pm

    Isn’t there simply a default layout that would be instantiated in the case of calling super()?

    There is and it is a FlowLayout (you can look at the JPanel constructor javadoc or source to see that for yourself). FlowLayout gives the components its preferred size and does not stretch it.

    Instead of a GridLayout you could also use a BorderLayout and add to the CENTER.

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

Sidebar

Related Questions

Why the following code Based on Mozilla example does not work? Tried with Firefox
I installed the following component by MacPorts: p5-image-info @1.16 (perl, graphics) Extract meta information
I have the following component @ ?option=com_tmportal&module=user&task=main I've enabled url rewriting and setup the
I have a component called a TableDataViewer that contains the following pieces of data
In following code, I have one large component, and I'd like only the level4
I defined a custom component and tried to use binding as the following: <ui:composition
I am supposed to design a component which should achieve the following tasks by
I have the following XElement: <Assembly name=3> <Component name=2 /> </Assembly> I would like
When using a standard asp:Button component, it is necessary to use the following technique
Considering this article Developing a MVC component for Joomla , following is the code

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.