Java JTable Scroll updateScrollMode(JScrollPane scroll, JTable table)

Here you can find the source of updateScrollMode(JScrollPane scroll, JTable table)

Description

Checks the size of the table and of the scroll bar where it is contained, and depending on it updates the auto resize mode.

License

Open Source License

Parameter

Parameter Description
scroll the scroll pane containing the table.
table the table.

Declaration

public static void updateScrollMode(JScrollPane scroll, JTable table) 

Method Source Code

//package com.java2s;
/*//  w  w w  .  j  av  a 2  s  .c om
 * CDDL HEADER START
 *
 * The contents of this file are subject to the terms of the
 * Common Development and Distribution License, Version 1.0 only
 * (the "License").  You may not use this file except in compliance
 * with the License.
 *
 * You can obtain a copy of the license at legal-notices/CDDLv1_0.txt
 * or http://forgerock.org/license/CDDLv1.0.html.
 * See the License for the specific language governing permissions
 * and limitations under the License.
 *
 * When distributing Covered Code, include this CDDL HEADER in each
 * file and include the License file at legal-notices/CDDLv1_0.txt.
 * If applicable, add the following below this CDDL HEADER, with the
 * fields enclosed by brackets "[]" replaced with your own identifying
 * information:
 *      Portions Copyright [yyyy] [name of copyright owner]
 *
 * CDDL HEADER END
 *
 *
 *      Copyright 2008-2010 Sun Microsystems, Inc.
 *      Portions Copyright 2011-2015 ForgeRock AS
 */

import javax.swing.JScrollPane;
import javax.swing.JTable;

public class Main {
    /**
     * Checks the size of the table and of the scroll bar where it is contained,
     * and depending on it updates the auto resize mode.
     * @param scroll the scroll pane containing the table.
     * @param table the table.
     */
    public static void updateScrollMode(JScrollPane scroll, JTable table) {
        int width1 = table.getPreferredScrollableViewportSize().width;
        int width2 = scroll.getViewport().getWidth();

        if (width1 > width2) {
            table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
        } else {
            table.setAutoResizeMode(JTable.AUTO_RESIZE_SUBSEQUENT_COLUMNS);
        }
    }
}

Related

  1. selectAndScrollToPosition(JTable table, int index0, int index1)
  2. selectRow(int row, JTable table, JScrollPane pane)
  3. selectRow(JTable table, int row, boolean bScroll)
  4. showMessageDialogInScrollableUneditableTextArea( java.awt.Component owner, String text, String title, int messageType, final int maxPreferredWidth, final int maxPreferredHeight)
  5. tableCenterScroll(JPanel panel, JTable table, int row)