use of javax.swing.table.DefaultTableColumnModel in project zencash-swing-wallet-ui by ZencashOfficial.
the class AddressBookPanel method buildTablePanel.
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);
// one at a time
table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
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;
}
use of javax.swing.table.DefaultTableColumnModel in project mafscaling by vimsh.
the class LogStats method createDataPanel.
private void createDataPanel(JPanel dataPanel) {
TableColumnModel dataTableModel = new DefaultTableColumnModel();
dataTableModel.addColumn(new TableColumn(0, 250));
dataTable = new JTable() {
private static final long serialVersionUID = 6526901361175099297L;
public boolean isCellEditable(int row, int column) {
return false;
}
};
dataTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
dataTable.setColumnSelectionAllowed(true);
dataTable.setCellSelectionEnabled(true);
dataTable.setBorder(new LineBorder(new Color(0, 0, 0)));
dataTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
dataTable.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
dataTable.setModel(new DefaultTableModel(DataTableRowCount, DataTableColumnCount));
dataTable.setTableHeader(null);
Utils.initializeTable(dataTable, ColumnWidth);
Format[][] formatMatrix = { { new DecimalFormat("0.00"), new DecimalFormat("0.00") } };
NumberFormatRenderer renderer = (NumberFormatRenderer) dataTable.getDefaultRenderer(Object.class);
renderer.setFormats(formatMatrix);
GridBagConstraints gbc_dataTable = new GridBagConstraints();
gbc_dataTable.insets = insets3;
gbc_dataTable.anchor = GridBagConstraints.PAGE_START;
gbc_dataTable.fill = GridBagConstraints.BOTH;
gbc_dataTable.weightx = 1.0;
gbc_dataTable.weighty = 1.0;
gbc_dataTable.gridx = 0;
gbc_dataTable.gridy = 1;
gbc_dataTable.gridwidth = 14;
JScrollPane scrollPane = new JScrollPane(dataTable);
dataPanel.add(scrollPane, gbc_dataTable);
excelAdapter.addTable(dataTable, false, true, true, true, true, true, true, true, true);
}
use of javax.swing.table.DefaultTableColumnModel in project mafscaling by vimsh.
the class ACompCalc method createDataTable.
private JTable createDataTable(JPanel panel, String tableName, int colCount, int rowCount, int gridx, int gridy, boolean isOriginalTable, boolean extendRows, boolean extendCols) {
final JTable table;
ExcelAdapter excelAdapter;
if (isOriginalTable) {
table = new JTable() {
private static final long serialVersionUID = 3218402382894083287L;
public boolean isCellEditable(int row, int column) {
return false;
}
};
excelAdapter = new ExcelAdapter() {
protected void onPaste(JTable table, boolean extendRows, boolean extendCols) {
if (table.getSelectedRows() == null || table.getSelectedRows().length == 0 || table.getSelectedColumns() == null || table.getSelectedColumns().length == 0)
return;
if (table.getSelectedRows()[0] != 0 || table.getSelectedColumns()[0] != 0) {
JOptionPane.showMessageDialog(null, "Please paste copied table into the first cell", "Error", JOptionPane.ERROR_MESSAGE);
return;
}
super.onPaste(table, extendRows, extendCols);
validateTable(table);
clearRunTables();
}
};
excelAdapter.addTable(table, false, true, false, false, true, true, false, extendRows, extendCols);
excelAdapterList.add(excelAdapter);
} else {
table = new JTable() {
private static final long serialVersionUID = -3754572906310312568L;
public boolean isCellEditable(int row, int column) {
return isNonOriginalTableCellEditable(row, column);
}
public Component prepareEditor(TableCellEditor editor, int row, int column) {
Component c = super.prepareEditor(editor, row, column);
if (c instanceof JTextComponent)
((JTextComponent) c).selectAll();
return c;
}
};
excelAdapter = new ExcelAdapter();
excelAdapter.addTable(table, false, true, false, false, true, true, false, false, false);
excelAdapterList.add(excelAdapter);
}
DefaultTableColumnModel tableModel = new DefaultTableColumnModel();
final TableColumn tableColumn = new TableColumn(0, (colCount == 1 ? ColumnWidth : TableWidth));
tableColumn.setHeaderValue(tableName);
tableModel.addColumn(tableColumn);
JTableHeader lblTableHeaderName = table.getTableHeader();
lblTableHeaderName.setColumnModel(tableModel);
lblTableHeaderName.setReorderingAllowed(false);
DefaultTableCellRenderer headerRenderer = (DefaultTableCellRenderer) lblTableHeaderName.getDefaultRenderer();
headerRenderer.setHorizontalAlignment(SwingConstants.LEFT);
GridBagConstraints gbc_lblTableName = new GridBagConstraints();
gbc_lblTableName.insets = new Insets((gridy == 0 ? 0 : 5), 0, 0, 0);
gbc_lblTableName.anchor = GridBagConstraints.NORTHWEST;
gbc_lblTableName.fill = GridBagConstraints.HORIZONTAL;
gbc_lblTableName.gridx = gridx;
gbc_lblTableName.gridy = gridy;
panel.add(lblTableHeaderName, gbc_lblTableName);
table.addComponentListener(new ComponentAdapter() {
@Override
public void componentResized(ComponentEvent e) {
tableColumn.setWidth(table.getWidth());
}
});
table.addMouseListener(new MouseAdapter() {
public void mousePressed(MouseEvent event) {
JTable eventTable = (JTable) event.getSource();
int colIdx = eventTable.getSelectedColumn();
int rowIdx = eventTable.getSelectedRow();
JTable[] tables = new JTable[] { origTable, newTable, corrTable, corrCountTable };
for (JTable t : tables) {
if (t == null || t == eventTable)
continue;
if (t.getColumnCount() - 1 >= colIdx && t.getRowCount() - 1 >= rowIdx) {
t.setColumnSelectionInterval(colIdx, colIdx);
t.setRowSelectionInterval(rowIdx, rowIdx);
}
}
}
public void mouseReleased(MouseEvent event) {
JTable eventTable = (JTable) event.getSource();
int[] cols = eventTable.getSelectedColumns();
int[] rows = eventTable.getSelectedRows();
int lastColIdx = cols.length - 1;
int lastRowIdx = rows.length - 1;
JTable[] tables = new JTable[] { origTable, newTable, corrTable, corrCountTable };
for (JTable t : tables) {
if (t == null || t == eventTable)
continue;
if (t.getColumnCount() - 1 >= cols[lastColIdx] && t.getRowCount() - 1 >= rows[lastRowIdx]) {
t.setColumnSelectionInterval(cols[0], cols[lastColIdx]);
t.setRowSelectionInterval(rows[0], rows[lastRowIdx]);
}
}
}
});
table.setName(tableName);
table.getTableHeader().setReorderingAllowed(false);
table.setColumnSelectionAllowed(true);
table.setCellSelectionEnabled(true);
table.setBorder(new LineBorder(new Color(0, 0, 0)));
table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
table.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
table.setModel(new DefaultTableModel(rowCount, colCount));
table.putClientProperty("terminateEditOnFocusLost", true);
Utils.initializeTable(table, ColumnWidth);
formatTable(table);
GridBagConstraints gbc_table = new GridBagConstraints();
gbc_table.insets = insets0;
gbc_table.anchor = GridBagConstraints.NORTHWEST;
gbc_table.gridx = gridx;
gbc_table.gridy = gridy + 1;
panel.add(table, gbc_table);
return table;
}
use of javax.swing.table.DefaultTableColumnModel in project gitblit by gitblit.
the class Utils method packColumn.
// Sets the preferred width of the visible 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).
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);
}
use of javax.swing.table.DefaultTableColumnModel in project zaproxy by zaproxy.
the class ParamsPanel method setParamsTableColumnSizes.
private void setParamsTableColumnSizes() {
for (int i = 0; i < paramsTable.getColumnCount(); i++) {
DefaultTableColumnModel colModel = (DefaultTableColumnModel) paramsTable.getColumnModel();
TableColumn col = colModel.getColumn(i);
int width = 0;
TableCellRenderer renderer = col.getHeaderRenderer();
if (renderer == null) {
renderer = paramsTable.getTableHeader().getDefaultRenderer();
}
Component comp = renderer.getTableCellRendererComponent(paramsTable, col.getHeaderValue(), false, false, 0, 0);
width = comp.getPreferredSize().width;
col.setPreferredWidth(width + 2);
}
// value
paramsTable.getColumnModel().getColumn(6).setPreferredWidth(999);
}
Aggregations