use of javax.swing.table.TableColumnModel in project intellij-community by JetBrains.
the class BaseTableView method restore.
public static void restore(final Storage storage, final JTable table) {
final TableColumnModel columnModel = table.getTableHeader().getColumnModel();
int index = 0;
final ArrayList<String> columnIndices = new ArrayList<>();
while (true) {
final String order = storage.get(orderPropertyName(index));
if (order == null)
break;
columnIndices.add(order);
index++;
if (index == table.getColumnCount())
break;
}
index = 0;
for (final String columnIndex : columnIndices) {
final int modelColumnIndex = indexbyModelIndex(columnModel, Integer.parseInt(columnIndex));
if (modelColumnIndex > 0 && modelColumnIndex < columnModel.getColumnCount()) {
columnModel.moveColumn(modelColumnIndex, index);
}
index++;
}
for (int i = 0; i < columnIndices.size(); i++) {
final String width = storage.get(widthPropertyName(i));
if (width != null && width.length() > 0) {
try {
columnModel.getColumn(i).setPreferredWidth(Integer.parseInt(width));
} catch (NumberFormatException e) {
LOG.error("Bad width: " + width + " at column: " + i + " from: " + storage + " actual columns count: " + columnModel.getColumnCount() + " info count: " + columnIndices.size(), e);
}
}
}
}
use of javax.swing.table.TableColumnModel in project intellij-community by JetBrains.
the class BaseTableView method store.
public static void store(final Storage storage, final JTable table) {
final TableColumnModel model = table.getTableHeader().getColumnModel();
final int columnCount = model.getColumnCount();
final boolean[] storedColumns = new boolean[columnCount];
Arrays.fill(storedColumns, false);
for (int i = 0; i < columnCount; i++) {
final TableColumn column = model.getColumn(i);
storage.put(widthPropertyName(i), String.valueOf(column.getWidth()));
final int modelIndex = column.getModelIndex();
storage.put(orderPropertyName(i), String.valueOf(modelIndex));
if (storedColumns[modelIndex]) {
LOG.error("columnCount: " + columnCount + " current: " + i + " modelINdex: " + modelIndex);
}
storedColumns[modelIndex] = true;
}
}
use of javax.swing.table.TableColumnModel in project android by JetBrains.
the class TranslationsEditorTest method setModel.
@Test
public void setModel() {
StringResourceTable table = (StringResourceTable) myTranslationsEditor.getTable().target();
OptionalInt optionalWidth = table.getKeyColumnPreferredWidth();
TableColumnModel model = table.getColumnModel();
assertTrue(optionalWidth.isPresent());
assertEquals(optionalWidth.getAsInt(), model.getColumn(KEY_COLUMN).getPreferredWidth());
optionalWidth = table.getDefaultValueAndLocaleColumnPreferredWidths();
int width = optionalWidth.getAsInt();
assertTrue(optionalWidth.isPresent());
IntStream.range(DEFAULT_VALUE_COLUMN, table.getColumnCount()).mapToObj(model::getColumn).forEach(column -> assertEquals(width, column.getPreferredWidth()));
}
use of javax.swing.table.TableColumnModel in project android by JetBrains.
the class SdkUpdaterConfigPanel method resizeColumnsToFit.
/**
* Helper to size a table's columns to fit their normal contents.
*/
protected static void resizeColumnsToFit(JTable table) {
TableColumnModel columnModel = table.getColumnModel();
for (int column = 1; column < table.getColumnCount(); column++) {
int width = 50;
for (int row = 0; row < table.getRowCount(); row++) {
TableCellRenderer renderer = table.getCellRenderer(row, column);
Component comp = table.prepareRenderer(renderer, row, column);
width = Math.max(comp.getPreferredSize().width + 1, width);
}
columnModel.getColumn(column).setPreferredWidth(width);
}
}
use of javax.swing.table.TableColumnModel in project JMRI by JMRI.
the class LRouteTableAction method makeColumns.
/*
* Utility for addPressed
*/
JScrollPane makeColumns(JTable table, JComboBox<String> box, boolean specialBox) {
table.setRowSelectionAllowed(false);
//table.setPreferredScrollableViewportSize(new java.awt.Dimension(250,450));
TableColumnModel columnModel = table.getColumnModel();
TableColumn sNameColumnT = columnModel.getColumn(RouteElementModel.SNAME_COLUMN);
sNameColumnT.setResizable(true);
sNameColumnT.setMinWidth(75);
//sNameColumnT.setMaxWidth(110);
TableColumn uNameColumnT = columnModel.getColumn(RouteElementModel.UNAME_COLUMN);
uNameColumnT.setResizable(true);
uNameColumnT.setMinWidth(75);
//uNameColumnT.setMaxWidth(260);
TableColumn typeColumnT = columnModel.getColumn(RouteElementModel.TYPE_COLUMN);
typeColumnT.setResizable(true);
typeColumnT.setMinWidth(50);
//typeColumnT.setMaxWidth(110);
TableColumn includeColumnT = columnModel.getColumn(RouteElementModel.INCLUDE_COLUMN);
includeColumnT.setResizable(false);
includeColumnT.setMinWidth(30);
includeColumnT.setMaxWidth(60);
TableColumn stateColumnT = columnModel.getColumn(RouteElementModel.STATE_COLUMN);
if (specialBox) {
box = new JComboBox<>();
stateColumnT.setCellEditor(new ComboBoxCellEditor(box));
} else {
stateColumnT.setCellEditor(new DefaultCellEditor(box));
}
stateColumnT.setResizable(false);
stateColumnT.setMinWidth(75);
return new JScrollPane(table);
}
Aggregations