本文整理匯總了Java中javax.swing.table.DefaultTableColumnModel.getColumn方法的典型用法代碼示例。如果您正苦於以下問題:Java DefaultTableColumnModel.getColumn方法的具體用法?Java DefaultTableColumnModel.getColumn怎麽用?Java DefaultTableColumnModel.getColumn使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.swing.table.DefaultTableColumnModel
的用法示例。
在下文中一共展示了DefaultTableColumnModel.getColumn方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: packColumn
import javax.swing.table.DefaultTableColumnModel; //導入方法依賴的package包/類
private static void packColumn(JTable table, int vColIndex, int margin) {
DefaultTableColumnModel colModel = (DefaultTableColumnModel) table.
getColumnModel();
TableColumn col = colModel.getColumn(vColIndex);
int width; // Obtém a largura do cabeçalho da coluna
TableCellRenderer renderer = col.getHeaderRenderer();
if (renderer == null) {
renderer = table.getTableHeader().getDefaultRenderer();
}
Component comp = renderer.getTableCellRendererComponent(
table, col.getHeaderValue(), false, false, 0, 0);
width = comp.getPreferredSize().width; // Obtém a largura maxima da coluna de dados
for (int r = 0; r < table.getRowCount(); r++) {
renderer = table.getCellRenderer(r, vColIndex);
comp = renderer.getTableCellRendererComponent(
table, table.getValueAt(r, vColIndex), false, false, r,
vColIndex);
width = Math.max(width, comp.getPreferredSize().width);
}
width += 2 * margin; // Configura a largura
col.setPreferredWidth(width);
}
示例2: autoResizeColWidth
import javax.swing.table.DefaultTableColumnModel; //導入方法依賴的package包/類
public static JTable autoResizeColWidth(JTable table, int extraSpaceToColumn) {
if (extraSpaceToColumn < 0 || extraSpaceToColumn >= table.getColumnCount()) {
throw new IllegalArgumentException("Illegal Column index. Table " + table.getName()
+ " has " + table.getColumnCount()
+ " columns. Can't set extra space to column " + extraSpaceToColumn);
}
int totalWidth = autoResizeColWidthNoFill(table);
int availableWidth = table.getParent().getWidth();
if (totalWidth >= availableWidth) {
return table;
}
int increaseBy = availableWidth - totalWidth;
DefaultTableColumnModel colModel = (DefaultTableColumnModel) table.getColumnModel();
TableColumn col = colModel.getColumn(extraSpaceToColumn);
int oldWidth = col.getPreferredWidth();
col.setPreferredWidth(oldWidth + increaseBy);
return table;
}
示例3: getPreferredAccessionColumnWidth
import javax.swing.table.DefaultTableColumnModel; //導入方法依賴的package包/類
/**
* Gets the preferred width of the column specified by colIndex. The column
* will be just wide enough to show the column head and the widest cell in
* the column. Margin pixels are added to the left and right (resulting in
* an additional width of 2*margin pixels. Returns null if the max width
* cannot be set.
*
* @param table the table
* @param colIndex the colum index
* @param margin the margin to add
* @return the preferred width of the column
*/
public Integer getPreferredAccessionColumnWidth(JTable table, int colIndex, int margin) {
DefaultTableColumnModel colModel = (DefaultTableColumnModel) table.getColumnModel();
TableColumn col = colModel.getColumn(colIndex);
// get width of column header
TableCellRenderer renderer = col.getHeaderRenderer();
if (renderer == null) {
renderer = table.getTableHeader().getDefaultRenderer();
}
Component comp = renderer.getTableCellRendererComponent(table, col.getHeaderValue(), false, false, 0, 0);
int width = comp.getPreferredSize().width;
// add margin
width += 2 * margin;
return width;
}
示例4: setTableColumnWidth
import javax.swing.table.DefaultTableColumnModel; //導入方法依賴的package包/類
/**
* 要求Byte/FLOP算出結果テーブル列幅を設定する.<br/>
* 要求Byte/FLOP算出結果テーブルはすべて固定列幅とする
* @param columnModel テーブル列モデル
*/
public void setTableColumnWidth(DefaultTableColumnModel columnModel) {
for (int i=0; i<columnModel.getColumnCount(); i++) {
// 列取得
TableColumn column = columnModel.getColumn(i);
if (HEADER_COLUMNS_PREFERREDWIDTH.length >= i) {
if (HEADER_COLUMNS_PREFERREDWIDTH[i] >= 0) {
//column.setMinWidth(HEADER_COLUMNS_PREFERREDWIDTH[i]);
//column.setMaxWidth(HEADER_COLUMNS_PREFERREDWIDTH[i]);
column.setPreferredWidth(HEADER_COLUMNS_PREFERREDWIDTH[i]);
column.setResizable(true);
}
else {
column.setMinWidth(0);
column.setMaxWidth(0);
column.setPreferredWidth(0);
column.setResizable(false);
}
}
}
}
示例5: setTableColumnWidth
import javax.swing.table.DefaultTableColumnModel; //導入方法依賴的package包/類
/**
* ブロック演算カウントテーブル列幅を設定する.<br/>
* 演算カウントテーブルはすべて固定列幅とする
* @param columnModel テーブル列モデル
*/
public void setTableColumnWidth(DefaultTableColumnModel columnModel) {
for (int i=0; i<columnModel.getColumnCount(); i++) {
// 列取得
TableColumn column = columnModel.getColumn(i);
if (HEADER_COLUMNS_PREFERREDWIDTH.length >= i) {
if (HEADER_COLUMNS_PREFERREDWIDTH[i] >= 0) {
column.setMinWidth(HEADER_COLUMNS_PREFERREDWIDTH[i]);
column.setMaxWidth(HEADER_COLUMNS_PREFERREDWIDTH[i]);
column.setPreferredWidth(HEADER_COLUMNS_PREFERREDWIDTH[i]);
column.setResizable(false);
}
else {
column.setMinWidth(0);
column.setMaxWidth(0);
column.setPreferredWidth(0);
column.setResizable(false);
}
}
}
}
示例6: setTableColumnWidth
import javax.swing.table.DefaultTableColumnModel; //導入方法依賴的package包/類
/**
* 列幅を設定する
* @param columnModel テーブル列モデル
*/
public void setTableColumnWidth(DefaultTableColumnModel columnModel) {
for (int i=0; i<columnModel.getColumnCount(); i++) {
// 列取得
TableColumn column = columnModel.getColumn(i);
if (HEADER_COLUMNS_PREFERREDWIDTH.length >= i) {
if (HEADER_COLUMNS_PREFERREDWIDTH[i] >= 0) {
column.setPreferredWidth(HEADER_COLUMNS_PREFERREDWIDTH[i]);
}
else {
column.setMinWidth(0);
column.setMaxWidth(0);
column.setPreferredWidth(0);
column.setResizable(false);
}
}
if (HEADER_COLUMNS_MINWIDTH.length >= i) {
if (HEADER_COLUMNS_MINWIDTH[i] >= 0) {
column.setMinWidth(HEADER_COLUMNS_MINWIDTH[i]);
}
}
}
}
示例7: setTableColumnWidth
import javax.swing.table.DefaultTableColumnModel; //導入方法依賴的package包/類
/**
* 列幅を設定する
* @param columnModel テーブル列モデル
*/
public void setTableColumnWidth(DefaultTableColumnModel columnModel) {
boolean[] visibled = getVisibledColumns();
int[] preferredWidth = getHeaderColumnsPreferredWidth();
int[] minWidth = getHeaderColumnsMinWidth();
for (int i=0; i<columnModel.getColumnCount(); i++) {
// 列取得
TableColumn column = columnModel.getColumn(i);
if (preferredWidth.length >= i) {
if (preferredWidth[i] >= 0 && visibled[i]) {
column.setPreferredWidth(preferredWidth[i]);
}
else {
column.setMinWidth(0);
column.setMaxWidth(0);
column.setPreferredWidth(0);
column.setResizable(false);
}
}
if (minWidth.length > i) {
if (minWidth[i] >= 0) {
column.setMinWidth(minWidth[i]);
}
}
}
}
示例8: adjustColumnSizes
import javax.swing.table.DefaultTableColumnModel; //導入方法依賴的package包/類
private void adjustColumnSizes(JTable table, int column, int margin) {
DefaultTableColumnModel colModel = (DefaultTableColumnModel) table.getColumnModel();
TableColumn col = colModel.getColumn(column);
int width;
TableCellRenderer renderer = col.getHeaderRenderer();
if (renderer == null) {
renderer = table.getTableHeader().getDefaultRenderer();
}
Component comp = renderer.getTableCellRendererComponent(table, col.getHeaderValue(), false, false, 0, 0);
width = comp.getPreferredSize().width;
for (int r = 0; r < table.getRowCount(); r++) {
renderer = table.getCellRenderer(r, column);
comp = renderer.getTableCellRendererComponent(table, table.getValueAt(r, column), false, false, r, column);
int currentWidth = comp.getPreferredSize().width;
width = Math.max(width, currentWidth);
}
width += 2 * margin;
col.setPreferredWidth(width);
col.setWidth(width);
}
示例9: adjustColumnSizes
import javax.swing.table.DefaultTableColumnModel; //導入方法依賴的package包/類
/**
* Method sets columns width to the widest value
* @param table
* @param column
* @param margin
*/
public static void adjustColumnSizes(JTable table, int column, int margin) {
DefaultTableColumnModel colModel = (DefaultTableColumnModel) table.getColumnModel();
TableColumn col = colModel.getColumn(column);
int width;
TableCellRenderer renderer = col.getHeaderRenderer();
if (renderer == null)
renderer = table.getTableHeader().getDefaultRenderer();
Component comp = renderer.getTableCellRendererComponent(table, col.getHeaderValue(), false, false, 0, 0);
width = comp.getPreferredSize().width;
for (int r = 0; r < table.getRowCount(); ++r) {
renderer = table.getCellRenderer(r, column);
comp = renderer.getTableCellRendererComponent(table, table.getValueAt(r, column), false, false, r, column);
int currentWidth = comp.getPreferredSize().width;
width = Math.max(width, currentWidth);
}
width += 2 * margin;
col.setPreferredWidth(width);
}
示例10: getPreferredColumnWidth
import javax.swing.table.DefaultTableColumnModel; //導入方法依賴的package包/類
/**
* Gets the preferred width of the column specified by vColIndex. The column
* will be just wide enough to show the column head and the widest cell in
* the column. Margin pixels are added to the left and right (resulting in
* an additional width of 2*margin pixels.
*
* @param table the table
* @param colIndex the colum index
* @param margin the margin to add
* @return the preferred width of the column
*/
public int getPreferredColumnWidth(JTable table, int colIndex, int margin) {
DefaultTableColumnModel colModel = (DefaultTableColumnModel) table.getColumnModel();
TableColumn col = colModel.getColumn(colIndex);
// get width of column header
TableCellRenderer renderer = col.getHeaderRenderer();
if (renderer == null) {
renderer = table.getTableHeader().getDefaultRenderer();
}
Component comp = renderer.getTableCellRendererComponent(table, col.getHeaderValue(), false, false, 0, 0);
int width = comp.getPreferredSize().width;
// get maximum width of column data
for (int r = 0; r < table.getRowCount(); r++) {
renderer = table.getCellRenderer(r, colIndex);
comp = renderer.getTableCellRendererComponent(
table, table.getValueAt(r, colIndex), false, false, r, colIndex);
width = Math.max(width, comp.getPreferredSize().width);
}
// add margin
width += 2 * margin;
return width;
}
示例11: adjustColumnSizes
import javax.swing.table.DefaultTableColumnModel; //導入方法依賴的package包/類
private void adjustColumnSizes() {
final DefaultTableColumnModel colModel = (DefaultTableColumnModel) getColumnModel();
for (int i = 0; i < getColumnCount(); i++) {
final TableColumn col = colModel.getColumn(i);
int width;
TableCellRenderer renderer = col.getHeaderRenderer();
if (renderer == null) {
renderer = getTableHeader().getDefaultRenderer();
}
Component comp = renderer.getTableCellRendererComponent(this, col.getHeaderValue(), false, false, 0, 0);
width = comp.getPreferredSize().width;
for (int r = 0; r < getRowCount(); r++) {
renderer = getCellRenderer(r, i);
comp = renderer.getTableCellRendererComponent(this, this.getValueAt(r, i), false, false, r, i);
final int currentWidth = comp.getPreferredSize().width;
width = Math.max(width, currentWidth);
}
width += COLUMN_SPACE;
col.setPreferredWidth(width);
col.setWidth(width);
col.setMinWidth(width);
}
}
示例12: packColumn
import javax.swing.table.DefaultTableColumnModel; //導入方法依賴的package包/類
public void packColumn(JTable table, int vColIndex, int margin, boolean fixWidth) {
// TableModel model = table.getModel();
DefaultTableColumnModel colModel = (DefaultTableColumnModel) table.getColumnModel();
TableColumn col = colModel.getColumn(vColIndex);
int width = 0;
// Get width of column header
TableCellRenderer renderer = col.getHeaderRenderer();
if (renderer == null) {
renderer = table.getTableHeader().getDefaultRenderer();
}
Component comp = renderer.getTableCellRendererComponent(table, col.getHeaderValue(), false,
false, 0, 0);
width = comp.getPreferredSize().width;
// Get maximum width of column data
for (int r = 0; r < table.getRowCount(); r++) {
renderer = table.getCellRenderer(r, vColIndex);
comp = renderer.getTableCellRendererComponent(table, table.getValueAt(r, vColIndex),
false, false, r, vColIndex);
width = Math.max(width, comp.getPreferredSize().width);
}
// Add margin
width += 2 * margin;
// Set the width
col.setPreferredWidth(width);
if (fixWidth) {
col.setMaxWidth(width);
col.setMinWidth(width);
}
}
示例13: packColumn
import javax.swing.table.DefaultTableColumnModel; //導入方法依賴的package包/類
public static void packColumn(JTable table, int vColIndex, int margin) {
TableModel model = table.getModel();
DefaultTableColumnModel colModel = (DefaultTableColumnModel)table.getColumnModel();
TableColumn col = colModel.getColumn(vColIndex);
int width = 0;
// Get width of column header
TableCellRenderer renderer = col.getHeaderRenderer();
if (renderer == null) {
renderer = table.getTableHeader().getDefaultRenderer();
}
Component comp = renderer.getTableCellRendererComponent(
table, col.getHeaderValue(), false, false, 0, 0);
width = comp.getPreferredSize().width;
// Get maximum width of column data
for (int r=0; r<table.getRowCount(); r++) {
renderer = table.getCellRenderer(r, vColIndex);
comp = renderer.getTableCellRendererComponent(
table, table.getValueAt(r, vColIndex), false, false, r, vColIndex);
width = Math.max(width, comp.getPreferredSize().width);
}
// Add margin
width += 2*margin;
// Set the width
col.setPreferredWidth(width);
}
示例14: packColumnWidth
import javax.swing.table.DefaultTableColumnModel; //導入方法依賴的package包/類
/**
* Packs table column at the specified index to its preferred width.
*
* @param table table to process
* @param col column index
* @param margin column side margin
*/
public static void packColumnWidth ( final JTable table, final int col, final int margin )
{
final DefaultTableColumnModel columnModel = ( DefaultTableColumnModel ) table.getColumnModel ();
final TableColumn column = columnModel.getColumn ( col );
int width;
// Header renderer
TableCellRenderer renderer = column.getHeaderRenderer ();
if ( renderer == null )
{
renderer = table.getTableHeader ().getDefaultRenderer ();
}
// Header width
Component comp = renderer.getTableCellRendererComponent ( table, column.getHeaderValue (), false, false, 0, 0 );
width = comp.getPreferredSize ().width;
// Cells width
for ( int r = 0; r < table.getRowCount (); r++ )
{
renderer = table.getCellRenderer ( r, col );
comp = renderer.getTableCellRendererComponent ( table, table.getValueAt ( r, col ), false, false, r, col );
width = Math.max ( width, comp.getPreferredSize ().width );
}
// Margin
width += 2 * margin;
// Final values
column.setPreferredWidth ( width );
column.setWidth ( width );
}
示例15: packColumn
import javax.swing.table.DefaultTableColumnModel; //導入方法依賴的package包/類
private static void packColumn(JTable table, int vColIndex, int margin) {
DefaultTableColumnModel colModel = (DefaultTableColumnModel) table.getColumnModel();
TableColumn col = colModel.getColumn(vColIndex);
int width = 0;
// Get width of column header
TableCellRenderer renderer = col.getHeaderRenderer();
if (renderer == null) {
renderer = table.getTableHeader().getDefaultRenderer();
}
Component comp = renderer.getTableCellRendererComponent(table, col.getHeaderValue(), false,
false, 0, 0);
width = comp.getPreferredSize().width;
// Get maximum width of column data
for (int r = 0; r < table.getRowCount(); r++) {
renderer = table.getCellRenderer(r, vColIndex);
comp = renderer.getTableCellRendererComponent(table, table.getValueAt(r, vColIndex),
false, false, r, vColIndex);
width = Math.max(width, comp.getPreferredSize().width);
}
// Add margin
width += 2 * margin;
// Set the width
col.setPreferredWidth(width);
}