decodes.gui.TableColumnAdjuster Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of opendcs Show documentation
Show all versions of opendcs Show documentation
A collection of software for aggregatting and processing environmental data such as from NOAA GOES satellites.
The newest version!
package decodes.gui;
import javax.swing.*;
import javax.swing.table.*;
/**
Static utility to adjust column widths.
*/
public class TableColumnAdjuster
{
/**
* Adjusts widths of the table according to percentages that you supply
* in an array.
* @param table the JTable
* @param percent array of integers, one for each column.
*/
public static void adjustColumnWidths(JTable table, int[] percent)
{
int totalWidth = 0;
TableColumn tc[] = new TableColumn[percent.length];
// tableWidth = table.getWidth();
// Get total width of all columns
for(int i=0; i= 0; i--)
{
int w = (int)(totalWidth * (double)percent[i]/100.0);
tc[i].setPreferredWidth(w);
tc[i].setWidth(w);
}
}
}