Here you can find the source of getColumnWidths(final JTable table)
Parameter | Description |
---|---|
table | The table to collect column widths from |
public static String getColumnWidths(final JTable table)
//package com.java2s; /*// www .j a va 2 s . co m * jGnash, a personal finance application * Copyright (C) 2001-2017 Craig Cavanaugh * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ import java.util.Objects; import javax.swing.JTable; import javax.swing.table.TableColumnModel; public class Main { /** * Returns the column widths of a table in a formatted * {@code String}. * * @param table The table to collect column widths from * @return A String in the format "34 56 56 56" */ public static String getColumnWidths(final JTable table) { Objects.requireNonNull(table); TableColumnModel model = table.getColumnModel(); int count = model.getColumnCount(); StringBuilder buffer = new StringBuilder(); for (int i = 0; i < count; i++) { if (i > 0) { buffer.append(' '); } int index = table.convertColumnIndexToView(i); buffer.append(model.getColumn(index).getWidth()); } return buffer.toString(); } }