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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T14:50:07+00:00 2026-05-25T14:50:07+00:00

I have a JTable which is created with the use of an EventTableModel and

  • 0

I have a JTable which is created with the use of an EventTableModel and is in a JScrollPane. The EventTableModel takes live updates from an eventList and displays the result in the table. As new results come into the table and the new piece of information is displayed at the top of the table.

However, what I want to be able to do is freeze the table to show what is currently displayed when I press a button called ‘Lock Table’. This button should have the same effect as the eclipse console ‘Scroll Lock’, therefore as new items appear the current items should remain on the screen and not be pushed off as new items appear. But new items should still be added just not automatically scrolled to.

Does anyone know how I can try achieve this functionality. So that as update come in, the data that is on the table is not forced off screen, therefore focuses remain on the current data when the check box is pressed.

Thanks for any help.
Michael

  • 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-25T14:50:08+00:00Added an answer on May 25, 2026 at 2:50 pm

    Basic procedure (for inserting above the current display area)

    • install a TableModelListener on the table’s model
    • on enable lock: note the number of rows below the current visible rectangle
    • on receiving inserts while locked, scroll so that the number of rows below are kept constant

    some working code (using JXTable, as it has convenience method for scrolling, for a core table simply do the calculations yourself 🙂

    public static class ScrollLock {
        private JXTable table;
        private boolean blocked;
        private int rowsBelow;
    
        public ScrollLock(JXTable table) {
            this.table = table;
            table.getModel().addTableModelListener(getTableModelListener());
        }
    
        private TableModelListener getTableModelListener() {
            TableModelListener l = new TableModelListener() {
    
                @Override
                public void tableChanged(TableModelEvent e) {
                    if (!blocked) return;
                    if (e.getType() == TableModelEvent.INSERT) {
                        updateInsert(e.getFirstRow(), e.getLastRow());
                    }
                }
    
            };
            return l;
        }
    
        protected void updateInsert(int firstRow, int lastRow) {
            // PENDING: assumption is that insert always above
            // need additional logic for other cases
            SwingUtilities.invokeLater(new Runnable() {
                @Override
                public void run() {
                    Rectangle r = table.getVisibleRect();
                    int row =table.rowAtPoint(new Point(0, r.y + r.height));
                    int lastVisible = table.getRowCount() - rowsBelow;
                    table.scrollRowToVisible(lastVisible);
                }
            });
        }
    
        public void block() {
            Rectangle viewRect = table.getVisibleRect();
            int lastVisibleRow = table.rowAtPoint(new Point(0, viewRect.y + viewRect.height));
            rowsBelow = table.getRowCount() - lastVisibleRow;
            blocked = true;
        }
    
        public void unblock() {
            blocked = false;
            rowsBelow = -1;
        }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a JTable which is loaded from a data-structure using table model.The data-structure
I have a jTable which currently displays and allows editing of a database table,
In Java Swing I have created a JTable which uses a table model class
I have created a JTable, the table contains 4 rows, and for a specific
I have a standalone application in which I have a Jtable. In my table,
I have a Jtable on which I called the method table1.setAutoCreateRowSorter(true); . So this
Hi I an issue with editors in a JTable. I have a column which
I have a JTable that is within a JScrollPane. Rows are added to the
I have a JTable inside of a JScrollPane . I am creating a custom
I have a JTable that I want to use to display some data (a

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.