本文整理汇总了Java中javax.swing.table.DefaultTableColumnModel类的典型用法代码示例。如果您正苦于以下问题:Java DefaultTableColumnModel类的具体用法?Java DefaultTableColumnModel怎么用?Java DefaultTableColumnModel使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DefaultTableColumnModel类属于javax.swing.table包,在下文中一共展示了DefaultTableColumnModel类的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: buildTablePanel
import javax.swing.table.DefaultTableColumnModel; //导入依赖的package包/类
private JScrollPane buildTablePanel() {
table = new JTable(new AddressBookTableModel(),new DefaultTableColumnModel());
TableColumn nameColumn = new TableColumn(0);
TableColumn addressColumn = new TableColumn(1);
table.addColumn(nameColumn);
table.addColumn(addressColumn);
table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); // one at a time
table.getSelectionModel().addListSelectionListener(new AddressListSelectionListener());
table.addMouseListener(new AddressMouseListener());
// TODO: isolate in utility
TableCellRenderer renderer = table.getCellRenderer(0, 0);
Component comp = renderer.getTableCellRendererComponent(table, "123", false, false, 0, 0);
table.setRowHeight(new Double(comp.getPreferredSize().getHeight()).intValue() + 2);
JScrollPane scrollPane = new JScrollPane(table);
return scrollPane;
}
示例4: setReorderColumn
import javax.swing.table.DefaultTableColumnModel; //导入依赖的package包/类
/**
* Overriding the default re-ordering functionality.<p>
* Re-ordering allowed if both of the i.e <code>columnIndex,newIndex</code>
* are outside the limit.
*
* @param table the target tmodel
* @param lmt re-ordering limit
*/
public static void setReorderColumn(JTable table, final int lmt) {
table.setColumnModel(new DefaultTableColumnModel() {
private static final long serialVersionUID = 1L;
@Override
public void moveColumn(int columnIndex, int newIndex) {
if (columnIndex <= lmt) {
return;
} else if (newIndex <= lmt) {
return;
}
super.moveColumn(columnIndex, newIndex);
}
});
}
示例5: getDefaultTableColumnModel
import javax.swing.table.DefaultTableColumnModel; //导入依赖的package包/类
private final DefaultTableColumnModel getDefaultTableColumnModel() {
final DefaultTableColumnModel dtcm = new DefaultTableColumnModel();
final int[] sizeColumn = new int[]{36, 36, 106, 58, 42, 32, 43, 28};
final int size = sizeColumn.length;
TableColumn col = null;
for (int i = 0; i < size; i++) {
col = new TableColumn(i, sizeColumn[i]);
col.setHeaderValue(COLUMNS.get(i));
dtcm.addColumn(col);
}
return dtcm;
}
示例6: buildTablePanel
import javax.swing.table.DefaultTableColumnModel; //导入依赖的package包/类
private JScrollPane buildTablePanel() {
table = new JTable(new AddressBookTableModel(),new DefaultTableColumnModel());
TableColumn nameColumn = new TableColumn(0);
TableColumn addressColumn = new TableColumn(1);
table.addColumn(nameColumn);
table.addColumn(addressColumn);
table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); // one at a time
table.getSelectionModel().addListSelectionListener(new AddressListSelectionListener());
table.addMouseListener(new AddressMouseListener());
// TODO: isolate in utility
TableCellRenderer renderer = table.getCellRenderer(0, 0);
Component comp = renderer.getTableCellRendererComponent(table, "123", false, false, 0, 0);
table.setRowHeight(new Double(comp.getPreferredSize().getHeight()).intValue() + 2);
JScrollPane scrollPane = new JScrollPane(table);
return scrollPane;
}
示例7: PluginSummaryTable
import javax.swing.table.DefaultTableColumnModel; //导入依赖的package包/类
public PluginSummaryTable(PluginInfo[] pluginInfo, PluginStatus[] pluginStatus)
{
super(new MyTableModel(pluginInfo, pluginStatus));
setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
getTableHeader().setResizingAllowed(true);
getTableHeader().setReorderingAllowed(true);
setAutoCreateColumnsFromModel(false);
setAutoResizeMode(AUTO_RESIZE_LAST_COLUMN);
final TableColumnModel tcm = new DefaultTableColumnModel();
for (int i = 0; i < s_columnWidths.length; ++i)
{
final TableColumn col = new TableColumn(i, s_columnWidths[i]);
col.setHeaderValue(s_hdgs[i]);
tcm.addColumn(col);
}
setColumnModel(tcm);
}
示例8: UpdateSummaryTable
import javax.swing.table.DefaultTableColumnModel; //导入依赖的package包/类
public UpdateSummaryTable(List<ArtifactStatus> artifactStatus,
UpdateSummaryTableModel model) {
super(model);
_model = model;
_artifacts = artifactStatus;
setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
getTableHeader().setResizingAllowed(true);
getTableHeader().setReorderingAllowed(true);
setAutoCreateColumnsFromModel(false);
setAutoResizeMode(AUTO_RESIZE_LAST_COLUMN);
final TableColumnModel tcm = new DefaultTableColumnModel();
JComboBox _actionComboBox = new JComboBox();
for (int i = 0; i < model.getColumnCount(); ++i) {
final TableColumn col = new TableColumn(i, model.getColumnWidth(i));
col.setHeaderValue(model.getColumnName(i));
if (i == 3) {
col.setCellEditor(new DefaultCellEditor(initCbo(_actionComboBox)));
}
tcm.addColumn(col);
}
setColumnModel(tcm);
initPopup();
}
示例9: interactiveTestColumnControlColumnModel
import javax.swing.table.DefaultTableColumnModel; //导入依赖的package包/类
/**
* Issue ??: Column control on changing column model.
*
*/
public void interactiveTestColumnControlColumnModel() {
final JXTable table = new JXTable(10, 5);
table.setColumnControlVisible(true);
Action toggleAction = new AbstractAction("Set ColumnModel") {
@Override
public void actionPerformed(ActionEvent e) {
table.setColumnModel(new DefaultTableColumnModel());
table.setModel(new AncientSwingTeam());
setEnabled(false);
}
};
JXFrame frame = wrapWithScrollingInFrame(table,
"ColumnControl: set columnModel ext -> core default");
addAction(frame, toggleAction);
frame.setVisible(true);
}
示例10: interactiveTestColumnControlColumnModelExt
import javax.swing.table.DefaultTableColumnModel; //导入依赖的package包/类
/**
* Issue ??: Column control cancontrol update on changing column model.
*
*/
public void interactiveTestColumnControlColumnModelExt() {
final JXTable table = new JXTable();
table.setColumnModel(new DefaultTableColumnModel());
table.setModel(new DefaultTableModel(10, 5));
table.setColumnControlVisible(true);
Action toggleAction = new AbstractAction("Set ColumnModelExt") {
@Override
public void actionPerformed(ActionEvent e) {
table.setColumnModel(new DefaultTableColumnModelExt());
table.setModel(new AncientSwingTeam());
table.getColumnExt(0).setVisible(false);
setEnabled(false);
}
};
JXFrame frame = wrapWithScrollingInFrame(table,
"ColumnControl: set ColumnModel core -> modelExt");
addAction(frame, toggleAction);
frame.setVisible(true);
}
示例11: ExtColumnModel
import javax.swing.table.DefaultTableColumnModel; //导入依赖的package包/类
/**
* @param columnModel
*/
public ExtColumnModel(final TableColumnModel org) {
super();
this.setColumnMargin(org.getColumnMargin());
this.setColumnSelectionAllowed(org.getColumnSelectionAllowed());
this.setSelectionModel(org.getSelectionModel());
for (int i = 0; i < org.getColumnCount(); i++) {
this.addColumn(org.getColumn(i));
}
if (org instanceof DefaultTableColumnModel) {
for (final TableColumnModelListener cl : ((DefaultTableColumnModel) org).getColumnModelListeners()) {
this.addColumnModelListener(cl);
}
}
}
示例12: 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;
}
示例13: testGetSetColumnModel
import javax.swing.table.DefaultTableColumnModel; //导入依赖的package包/类
public void testGetSetColumnModel() throws Exception {
table = new JTable(3, 4);
DefaultTableColumnModel oldModel = (DefaultTableColumnModel) table.getColumnModel();
assertNotNull(oldModel);
assertEquals(2, oldModel.getColumnModelListeners().length);
assertEquals(table.getTableHeader(), oldModel.getColumnModelListeners()[0]);
assertEquals(table, oldModel.getColumnModelListeners()[1]);
DefaultTableColumnModel model = new DefaultTableColumnModel();
table.setColumnModel(model);
assertEquals(0, oldModel.getColumnModelListeners().length);
assertEquals(2, model.getColumnModelListeners().length);
assertEquals(0, table.getColumnModel().getColumnCount());
assertFalse(propertyChangeController.isChanged());
testExceptionalCase(new IllegalArgumentCase() {
@Override
public void exceptionalAction() throws Exception {
table.setColumnModel(null);
}
});
}
示例14: 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);
}
}
}
}
示例15: 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);
}
}
}
}