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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T11:30:52+00:00 2026-05-22T11:30:52+00:00

I have a JPanel containing 3 JScrollPanes(each contains a Jtable) added with a boxlayout,

  • 0

I have a JPanel containing 3 JScrollPanes(each contains a Jtable) added with a boxlayout, so I see 3 tables in a page and I load data dynamically, the code logic is almost same for 3 tables and only the column names and some cell rendering is different, For each tables I wanted to have auto scrolling to bottom of the table when new rows added to table, first 2 tables work perfect and scrollbar goes to bottom of table, but this last table’s scroll bar do weird things! I use exactly the same scrolling method for 3 tables but first 2 works this does not work!

Any ideas?

I removed some column adding code for clearity but this is the idea;

private JScrollPane fillThirdTable(ArrayList<DisplayVariable> displayList) {
    DefaultTableModel model = new DefaultTableModel();

    ToolTipTable answer = new ToolTipTable(model);

            answer.setRowHeight(60);
    answer.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
    answer.setSize(1300, 400);  
    DefaultTableCellRenderer dtcr = new DefaultTableCellRenderer();
    dtcr.setHorizontalAlignment(SwingConstants.CENTER);
    answer.getColumn("Display Variable ID").setCellRenderer(dtcr);

    JScrollPane scrollPane = null;
    for (DisplayVariable var : displayList) {

        model.addRow(new Object[] { id, shown, name, value });
        answer.setFillsViewportHeight(true);    
    }


    TableColumn c= answer.getColumnModel().getColumn(3);
    c.setCellRenderer(new MultiLineCellRenderer());

    TableColumn c2= answer.getColumnModel().getColumn(2);
    c2.setCellRenderer(new MultiLineCellRenderer());


    scrollPane = new JScrollPane(answer);
    scrollPane.setSize(1300, 400);

//here I call the method
    scrollToVisible(answer, (displayList.size()-1), 1);

    return scrollPane;

}

and this is the method for autoscrolling;

public void scrollToVisible(JTable table, int rowIndex, int vColIndex) {
    if (!(table.getParent() instanceof JViewport)) {
        return;
    }
    JViewport viewport = (JViewport)table.getParent();

    // This rectangle is relative to the table where the
    // northwest corner of cell (0,0) is always (0,0).
    Rectangle rect = table.getCellRect(rowIndex, vColIndex, true);

    // The location of the viewport relative to the table
    Point pt = viewport.getViewPosition();

    // Translate the cell location so that it is relative
    // to the view, assuming the northwest corner of the
    // view is (0,0)
    rect.setLocation(rect.x-pt.x, rect.y-pt.y);

    // Scroll the area into view
    viewport.scrollRectToVisible(rect);
}
  • 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-22T11:30:52+00:00Added an answer on May 22, 2026 at 11:30 am

    I just removed the “scrollPane.setSize(1300, 400)” and it worked

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

Sidebar

Related Questions

I have JPanel has already added to JFrame. And I have dynamically added JPanel.
I have a JFrame containing three JPanel. The first JPanel contains a JTextField and
I have a JPanel subclass on which I add buttons, labels, tables, etc. To
I have a JPanel which uses a BoxLayout in the X_AXIS direction. The problem
I have a JFrame that contains a display JPanel with JTextField and a control
We have a JPanel which contains multiple JPanels which contain JComponents (let's say JLabels
I have a JPanel, on it are added an image and label, in that
I have A Jpanel with A GridLayout inside. Now I added another Jpanel inside
I have a JPanel that contains an image. I want to draw rulers on
I have a JPanel and i am creating JButtons dynamically on runtime. I want

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.