use of javax.swing.table.DefaultTableCellRenderer in project adempiere by adempiere.
the class ResultTable method autoSize.
/**************************************************************************
* Size Columns
*/
private void autoSize() {
log.config("");
//
// making sure it fits in a column
final int SLACK = 8;
// max size of a column
final int MAXSIZE = 300;
//
TableColumnModel tcm = getColumnModel();
// For all columns
for (int col = 0; col < tcm.getColumnCount(); col++) {
TableColumn tc = tcm.getColumn(col);
// log.config( "Column=" + col, tc.getHeaderValue());
int width = 0;
// Header
TableCellRenderer renderer = tc.getHeaderRenderer();
if (renderer == null)
renderer = new DefaultTableCellRenderer();
Component comp = renderer.getTableCellRendererComponent(this, tc.getHeaderValue(), false, false, 0, 0);
// log.fine( "Hdr - preferred=" + comp.getPreferredSize().width + ", width=" + comp.getWidth());
width = comp.getPreferredSize().width + SLACK;
// Cells
// first 30 rows
int maxRow = Math.min(30, getRowCount());
for (int row = 0; row < maxRow; row++) {
renderer = getCellRenderer(row, col);
comp = renderer.getTableCellRendererComponent(this, getValueAt(row, col), false, false, row, col);
int rowWidth = comp.getPreferredSize().width + SLACK;
width = Math.max(width, rowWidth);
}
// Width not greater ..
width = Math.min(MAXSIZE, width);
tc.setPreferredWidth(width);
// log.fine( "width=" + width);
}
// for all columns
}
use of javax.swing.table.DefaultTableCellRenderer in project jabref by JabRef.
the class MainTable method getCellRenderer.
@Override
public TableCellRenderer getCellRenderer(int row, int column) {
int score = -3;
DefaultTableCellRenderer renderer = MainTable.defRenderer;
if ((model.getSearchState() != MainTableDataModel.DisplayOption.FLOAT) || matches(row, SearchMatcher.INSTANCE)) {
score++;
}
if ((model.getGroupingState() != MainTableDataModel.DisplayOption.FLOAT) || matches(row, GroupMatcher.INSTANCE)) {
score += 2;
}
// a very grayed out one for entries with -2
if (score < -1) {
if (column == 0) {
MainTable.veryGrayedOutNumberRenderer.setNumber(row);
renderer = MainTable.veryGrayedOutNumberRenderer;
} else {
renderer = MainTable.veryGrayedOutRenderer;
}
} else if (score == -1) {
if (column == 0) {
MainTable.grayedOutNumberRenderer.setNumber(row);
renderer = MainTable.grayedOutNumberRenderer;
} else {
renderer = MainTable.grayedOutRenderer;
}
} else if (column == 0) {
if (isComplete(row)) {
MainTable.compRenderer.setNumber(row);
int marking = isMarked(row);
if (marking > 0) {
marking = Math.min(marking, EntryMarker.MARK_COLOR_LEVELS);
renderer = MainTable.markedNumberRenderers.get(marking - 1);
MainTable.markedNumberRenderers.get(marking - 1).setNumber(row);
} else {
renderer = MainTable.compRenderer;
}
} else {
// Return a renderer with red background if the entry is incomplete.
MainTable.incRenderer.setNumber(row);
renderer = MainTable.incRenderer;
}
} else if (tableColorCodes || tableResolvedColorCodes) {
CellRendererMode status = getCellStatus(row, column, tableResolvedColorCodes);
if (status == CellRendererMode.REQUIRED) {
renderer = MainTable.reqRenderer;
} else if (status == CellRendererMode.OPTIONAL) {
renderer = MainTable.optRenderer;
} else if (status == CellRendererMode.RESOLVED) {
renderer = MainTable.resolvedRenderer;
}
}
// For MARKED feature:
int marking = isMarked(row);
if ((column != 0) && (marking > 0)) {
marking = Math.min(marking, EntryMarker.MARK_COLOR_LEVELS);
renderer = MainTable.markedRenderers.get(marking - 1);
}
return renderer;
}
use of javax.swing.table.DefaultTableCellRenderer in project processdash by dtuma.
the class TeamMemberListTable method prepareRenderer.
@Override
public Component prepareRenderer(TableCellRenderer renderer, int row, int column) {
Component result = super.prepareRenderer(renderer, row, column);
if (result instanceof DefaultTableCellRenderer) {
if (row == getSelectedRow() && column == getSelectedColumn())
;
else if (isCellEditable(row, column))
result.setBackground(getBackground());
else
result.setBackground(unmodifiableCellBackground);
}
return result;
}
use of javax.swing.table.DefaultTableCellRenderer in project megameklab by MegaMek.
the class TransportTab method initUI.
private void initUI() {
// $NON-NLS-1$
ResourceBundle resourceMap = ResourceBundle.getBundle("megameklab.resources.Tabs", new EncodeControl());
setLayout(new GridBagLayout());
GridBagConstraints gbc = new GridBagConstraints();
gbc.insets = new Insets(5, 5, 5, 5);
gbc.anchor = GridBagConstraints.NORTHWEST;
gbc.gridx = 0;
gbc.gridy = 0;
gbc.gridwidth = 2;
// $NON-NLS-1$
add(new JLabel(resourceMap.getString("TransportTab.lblCurrentBays.text")), gbc);
gbc.gridy++;
gbc.gridwidth = 1;
// $NON-NLS-1$
add(new JLabel(resourceMap.getString("TransportTab.lblMaxDoors.text")), gbc);
gbc.gridx = 1;
add(lblMaxDoors, gbc);
gbc.gridx = 0;
gbc.gridy++;
gbc.gridwidth = 1;
// $NON-NLS-1$
btnRemoveBay.setText(resourceMap.getString("TransportTab.btnRemoveBay.text"));
// $NON-NLS-1$
btnRemoveBay.setToolTipText(resourceMap.getString("TransportTab.btnRemoveBay.tooltip"));
add(btnRemoveBay, gbc);
btnRemoveBay.addActionListener(this);
gbc.gridx = 1;
// $NON-NLS-1$
btnAddToCargo.setText(resourceMap.getString("TransportTab.btnAddToCargo.text"));
// $NON-NLS-1$
btnAddToCargo.setToolTipText(resourceMap.getString("TransportTab.btnAddToCargo.tooltip"));
add(btnAddToCargo, gbc);
btnAddToCargo.addActionListener(this);
gbc.gridx = 0;
gbc.gridy++;
gbc.gridwidth = 3;
gbc.gridheight = GridBagConstraints.REMAINDER;
add(new JScrollPane(tblInstalled), gbc);
gbc.gridx = 3;
gbc.gridy = 0;
gbc.gridwidth = 1;
gbc.gridheight = 1;
// $NON-NLS-1$
add(new JLabel(resourceMap.getString("TransportTab.lblAvailableBays.text")), gbc);
gbc.gridy = 2;
// $NON-NLS-1$
btnAddBay.setText(resourceMap.getString("TransportTab.btnAddBay.text"));
// $NON-NLS-1$
btnAddBay.setToolTipText(resourceMap.getString("TransportTab.btnAddBay.tooltip"));
add(btnAddBay, gbc);
btnAddBay.addActionListener(this);
gbc.gridy++;
gbc.gridwidth = 2;
gbc.gridheight = GridBagConstraints.REMAINDER;
add(new JScrollPane(tblAvailable), gbc);
tblInstalled.setRowHeight(24);
TableColumn col = tblInstalled.getColumnModel().getColumn(InstalledBaysModel.COL_SIZE);
col.setCellEditor(new SpinnerCellEditor(InstalledBaysModel.COL_SIZE));
DefaultTableCellRenderer renderer = new DefaultTableCellRenderer();
// $NON-NLS-1$
renderer.setToolTipText(resourceMap.getString("TransportTab.colSize.tooltip"));
col.setCellRenderer(renderer);
col = tblInstalled.getColumnModel().getColumn(InstalledBaysModel.COL_DOORS);
col.setCellEditor(new SpinnerCellEditor(InstalledBaysModel.COL_DOORS));
renderer = new DefaultTableCellRenderer();
// $NON-NLS-1$
renderer.setToolTipText(resourceMap.getString("TransportTab.colDoors.tooltip"));
col.setCellRenderer(renderer);
col = tblInstalled.getColumnModel().getColumn(InstalledBaysModel.COL_TONNAGE);
renderer = new DefaultTableCellRenderer();
// $NON-NLS-1$
renderer.setToolTipText(resourceMap.getString("TransportTab.colTonnage.tooltip"));
col.setCellRenderer(renderer);
col = tblInstalled.getColumnModel().getColumn(InstalledBaysModel.COL_PERSONNEL);
renderer = new DefaultTableCellRenderer();
// $NON-NLS-1$
renderer.setToolTipText(resourceMap.getString("TransportTab.colPersonnel.tooltip"));
col.setCellRenderer(renderer);
tblInstalled.setShowGrid(false);
tblInstalled.setIntercellSpacing(new Dimension(0, 0));
tblAvailable.setShowGrid(false);
tblAvailable.setIntercellSpacing(new Dimension(0, 0));
tblInstalled.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
tblInstalled.getSelectionModel().addListSelectionListener(e -> checkButtons());
tblAvailable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
tblAvailable.getSelectionModel().addListSelectionListener(e -> checkButtons());
tblInstalled.setDragEnabled(true);
tblInstalled.setDropMode(DropMode.INSERT_ROWS);
tblInstalled.setTransferHandler(new BayReorderTransferHandler());
refresh();
}
use of javax.swing.table.DefaultTableCellRenderer in project n2a by frothga.
the class Table method createVisualization.
public Component createVisualization() {
JTable result = new JTable(new OutputTableModel());
result.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
((DefaultTableCellRenderer) result.getTableHeader().getDefaultRenderer()).setHorizontalAlignment(JLabel.LEFT);
FontMetrics fm = result.getFontMetrics(result.getFont());
int digitWidth = fm.charWidth('0');
TableColumnModel cols = result.getColumnModel();
for (int i = 0; i < columns.size(); i++) {
Column c = columns.get(i);
cols.getColumn(i).setPreferredWidth(Math.max(digitWidth * c.textWidth, fm.stringWidth(c.header) + digitWidth));
}
return result;
}
Aggregations