use of javax.swing.table.JTableHeader in project bb4-games by bb4.
the class PlayerHeadCellRenderer method getTableCellRendererComponent.
/**
* This method gets called each time a column header is rendered.
* @param row always -1
* @param isSelected always false.
* @param hasFocus always false.
*/
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
// Inherit the colors and font from the header component
if (table != null) {
JTableHeader header = table.getTableHeader();
if (header != null) {
setForeground(Outcome.PLAYER1_WON.getColor().darker());
setBackground(Color.WHITE);
setFont(header.getFont());
}
}
setText((value == null) ? "" : value.toString());
setToolTipText(getText());
setBorder(UIManager.getBorder("TableHeader.cellBorder"));
setHorizontalAlignment(JLabel.CENTER);
this.setFont(FONT);
return this;
}
use of javax.swing.table.JTableHeader in project bb4-games by bb4.
the class ResultHeaderCellRenderer method getTableCellRendererComponent.
/**
* This method gets called each time a column header is rendered.
* @param value column header value of column 'vColIndex'
* @param row always -1
* @param isSelected always false.
* @param hasFocus always false.
*/
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
// Inherit the colors and font from the header component
if (table != null) {
JTableHeader header = table.getTableHeader();
if (header != null) {
setForeground(Outcome.PLAYER2_WON.getColor().darker());
setBackground(Color.WHITE);
setFont(header.getFont());
}
}
if (value instanceof TextAndIcon) {
setIcon(((TextAndIcon) value).icon);
setText(((TextAndIcon) value).text);
} else {
setText((value == null) ? "" : value.toString());
setIcon(null);
}
setToolTipText(getText());
setBorder(UIManager.getBorder("TableHeader.cellBorder"));
setHorizontalAlignment(JLabel.CENTER);
this.setFont(FONT);
return this;
}
use of javax.swing.table.JTableHeader in project opennars by opennars.
the class TableHelper method layoutColumns.
public static void layoutColumns(JTable p_Table, boolean p_OnlyVisibleRows) {
int column = 0;
TableColumn c = null;
int firstRow = p_OnlyVisibleRows ? getFirstVisibleRow(p_Table) : 0;
int lastRow = p_OnlyVisibleRows ? getLastVisibleRow(p_Table) : (p_Table.getModel().getRowCount() - 1);
Dimension intercellSpacing = p_Table.getIntercellSpacing();
JTableHeader tableHeader = p_Table.getTableHeader();
for (java.util.Enumeration columns = tableHeader.getColumnModel().getColumns(); columns.hasMoreElements(); column++) {
c = (TableColumn) columns.nextElement();
Component component = (c.getHeaderRenderer() != null) ? c.getHeaderRenderer().getTableCellRendererComponent(p_Table, c.getHeaderValue(), false, false, -1, column) : tableHeader.getDefaultRenderer().getTableCellRendererComponent(p_Table, c.getHeaderValue(), false, false, -1, column);
int width = Math.max(c.getWidth(), component.getPreferredSize().width);
if (firstRow >= 0) {
for (int i = firstRow, d = lastRow; i <= d; i++) {
width = Math.max(width, p_Table.getCellRenderer(i, column).getTableCellRendererComponent(p_Table, p_Table.getModel().getValueAt(i, column), false, false, i, column).getPreferredSize().width + intercellSpacing.width);
}
}
c.setPreferredWidth(width);
c.setWidth(width);
}
}
use of javax.swing.table.JTableHeader in project chatty by chatty.
the class ExtendableDefaultTableHeaderCellRenderer method getTableCellRendererComponent.
/**
* Returns the default table header cell renderer.
* <P>
* If the column is sorted, the approapriate icon is retrieved from the
* current Look and Feel, and a border appropriate to a table header cell is
* applied.
* <P>
* Subclasses may overide this method to provide custom content or
* formatting.
*
* @param table the <code>JTable</code>.
* @param value the value to assign to the header cell
* @param isSelected This parameter is ignored.
* @param hasFocus This parameter is ignored.
* @param row This parameter is ignored.
* @param column the column of the header cell to render
* @return the default table header cell renderer
*/
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
JTableHeader tableHeader = table.getTableHeader();
if (tableHeader != null) {
setForeground(tableHeader.getForeground());
}
setIcon(getIcon(table, column));
setBorder(UIManager.getBorder("TableHeader.cellBorder"));
return this;
}
use of javax.swing.table.JTableHeader in project pmd by pmd.
the class GUI method makeMatchList.
private JComponent makeMatchList() {
resultsTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
@Override
public void valueChanged(ListSelectionEvent e) {
populateResultArea();
}
});
resultsTable.registerKeyboardAction(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
copyMatchListSelectionsToClipboard();
}
}, "Copy", COPY_KEY_STROKE, JComponent.WHEN_FOCUSED);
resultsTable.registerKeyboardAction(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
deleteMatchlistSelections();
}
}, "Del", DELETE_KEY_STROKE, JComponent.WHEN_FOCUSED);
int[] alignments = new int[matchColumns.length];
for (int i = 0; i < alignments.length; i++) {
alignments[i] = matchColumns[i].alignment();
}
resultsTable.setDefaultRenderer(Object.class, new AlignmentRenderer(alignments));
final JTableHeader header = resultsTable.getTableHeader();
header.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
sortOnColumn(header.columnAtPoint(new Point(e.getX(), e.getY())));
}
});
return new JScrollPane(resultsTable);
}
Aggregations