本文整理汇总了Java中javax.swing.table.TableColumn.getPreferredWidth方法的典型用法代码示例。如果您正苦于以下问题:Java TableColumn.getPreferredWidth方法的具体用法?Java TableColumn.getPreferredWidth怎么用?Java TableColumn.getPreferredWidth使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.table.TableColumn
的用法示例。
在下文中一共展示了TableColumn.getPreferredWidth方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getPreferredScrollableViewportSize
import javax.swing.table.TableColumn; //导入方法依赖的package包/类
@Override
public Dimension getPreferredScrollableViewportSize() {
if( needCalcRowHeight ) {
calcRowHeight( getOffscreenGraphics() );
prefSize = null;
}
if( null == prefSize ) {
Dimension dim = new Dimension();
for( int i=0; i<getColumnCount(); i++ ) {
TableColumn tc = getColumnModel().getColumn( i );
dim.width += tc.getPreferredWidth();
}
int rowCount = Math.min( MAX_VISIBLE_ROWS, getRowCount() );
dim.height = rowCount*getRowHeight();
Rectangle screen = Utilities.getUsableScreenBounds();
dim.width = Math.min( dim.width, screen.width-100 );
dim.height = Math.min( dim.height, screen.height-100 );
prefSize = dim;
}
return prefSize;
}
示例2: updateTableColumnSizes
import javax.swing.table.TableColumn; //导入方法依赖的package包/类
private void updateTableColumnSizes() {
ETable table = tableView.getTable();
Font font = tableView.getFont();
FontMetrics fm = tableView.getFontMetrics(font);
int maxCharWidth = fm.charWidth('A');
int editingBorder = 4;
TableColumnModel columnModel = table.getColumnModel();
TableColumn nameColumn = columnModel.getColumn(0);
nameColumn.setPreferredWidth(8 * maxCharWidth + editingBorder); // 8 chars for name
TableColumn keyColumn = columnModel.getColumn(1);
// Single char for key (but 3 chars to prevent "..." in column header)
keyColumn.setPreferredWidth(3 * maxCharWidth + editingBorder);
keyColumn.setMinWidth(keyColumn.getPreferredWidth());
TableColumn locationColumn = columnModel.getColumn(2);
Insets insets = tableView.getBorder().getBorderInsets(tableView);
int remainingWidth = tableView.getParent().getWidth() - insets.left - insets.right;
remainingWidth -= 2 * columnModel.getColumnMargin();
remainingWidth -= nameColumn.getPreferredWidth();
remainingWidth -= keyColumn.getPreferredWidth();
locationColumn.setPreferredWidth(remainingWidth); // remaining space for location
}
示例3: autoResizeColWidth
import javax.swing.table.TableColumn; //导入方法依赖的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;
}
示例4: DataTable
import javax.swing.table.TableColumn; //导入方法依赖的package包/类
public DataTable(TableModel model) {
super(model);
setSurrendersFocusOnKeystroke(true);
TableColumnModel cmodel = getColumnModel();
int i;
int ccount = model.getColumnCount();
int columnWidth;
int preferredWidth;
String columnName;
int width = 0;
for (i = 0; i < ccount; i++) {
TableColumn col = cmodel.getColumn(i);
Map cmap = ColumnItem.getColumnProperty(i);
col.setIdentifier(cmap.get("name")); //NOI18N
columnName = NbBundle.getMessage (CreateTableDialog.class, "CreateTable_" + i); //NOI18N
columnWidth = (new Double(getFontMetrics(getFont()).getStringBounds(columnName, getGraphics()).getWidth())).intValue() + 20;
if (cmap.containsKey("width")) { // NOI18N
if (((Integer)cmap.get("width")).intValue() < columnWidth)
col.setPreferredWidth(columnWidth);
else
col.setPreferredWidth(((Integer)cmap.get("width")).intValue()); // NOI18N
preferredWidth = col.getPreferredWidth();
}
if (cmap.containsKey("minwidth")) // NOI18N
if (((Integer)cmap.get("minwidth")).intValue() < columnWidth)
col.setMinWidth(columnWidth);
else
col.setMinWidth(((Integer)cmap.get("minwidth")).intValue()); // NOI18N
// if (cmap.containsKey("alignment")) {}
// if (cmap.containsKey("tip")) ((JComponent)col.getCellRenderer()).setToolTipText((String)cmap.get("tip"));
if (i < 7) { // the first 7 columns should be visible
width += col.getPreferredWidth();
}
}
width = Math.min(Math.max(width, 380), Toolkit.getDefaultToolkit().getScreenSize().width - 100);
setPreferredScrollableViewportSize(new Dimension(width, 150));
}
示例5: getPreferredSize
import javax.swing.table.TableColumn; //导入方法依赖的package包/类
/**
* Invokes the getPreferredSize method on each UI handled by this object.
*
* @param c the component whose preferred size is being queried; this
* argument is ignored.
* @return the dimension of the whole header
*/
@SuppressWarnings("unchecked")
public Dimension getPreferredSize(JComponent c) {
long width = 0;
Enumeration columns = header.getColumnModel().getColumns();
while (columns.hasMoreElements()) {
TableColumn aColumn = (TableColumn) columns.nextElement();
width = width + aColumn.getPreferredWidth();
}
return createHeaderSize(width);
}