use of javax.swing.table.JTableHeader in project com.revolsys.open by revolsys.
the class SortableTableCellHeaderRenderer method getTableCellRendererComponent.
@Override
public Component getTableCellRendererComponent(final JTable table, final Object value, final boolean isSelected, final boolean hasFocus, final int row, final int column) {
Icon icon = (Icon) UIManager.get("Table.naturalSortIcon");
boolean isPrint = false;
if (table != null) {
final JTableHeader header = table.getTableHeader();
if (header != null) {
Color foreground = null;
Color background = null;
if (hasFocus) {
foreground = (Color) UIManager.get("TableHeader.focusCellForeground");
background = (Color) UIManager.get("TableHeader.focusCellBackground");
}
if (foreground == null) {
foreground = header.getForeground();
}
if (background == null) {
background = header.getBackground();
}
setForeground(foreground);
setBackground(background);
setFont(header.getFont());
isPrint = header.isPaintingForPrint();
}
if (!isPrint) {
if (!this.horizontalTextPositionSet) {
setHorizontalTextPosition(10);
}
final SortOrder sortorder = getColumnSortOrder(table, column);
if (sortorder != null) {
switch(sortorder) {
case ASCENDING:
icon = (Icon) UIManager.get("Table.ascendingSortIcon");
break;
case DESCENDING:
icon = (Icon) UIManager.get("Table.descendingSortIcon");
break;
case UNSORTED:
icon = (Icon) UIManager.get("Table.naturalSortIcon");
break;
}
}
}
}
final String text = DataTypes.toString(value);
setText(text);
setIcon(icon);
this.sortArrow = icon;
Border border = null;
if (hasFocus) {
border = (Border) UIManager.get("TableHeader.focusCellBorder");
}
if (border == null) {
border = (Border) UIManager.get("TableHeader.cellBorder");
}
setBorder(border);
return this;
}
use of javax.swing.table.JTableHeader in project beast2 by CompEvol.
the class TaxonSetInputEditor method getContent.
private Component getContent(List<Taxon> taxonset) {
m_taxonset = taxonset;
m_taxonMap = new HashMap<>();
m_lineageset = new ArrayList<>();
for (Taxon taxonset2 : m_taxonset) {
if (taxonset2 instanceof TaxonSet) {
for (Taxon taxon : ((TaxonSet) taxonset2).taxonsetInput.get()) {
m_lineageset.add(taxon);
m_taxonMap.put(taxon.getID(), taxonset2.getID());
}
}
}
// set up table.
// special features: background shading of rows
// custom editor allowing only Date column to be edited.
m_model = new DefaultTableModel();
m_model.addColumn("Taxon");
m_model.addColumn("Species/Population");
taxonSetToModel();
m_table = new JTable(m_model) {
private static final long serialVersionUID = 1L;
// method that induces table row shading
@Override
public Component prepareRenderer(TableCellRenderer renderer, int Index_row, int Index_col) {
Component comp = super.prepareRenderer(renderer, Index_row, Index_col);
// even index, selected or not selected
if (isCellSelected(Index_row, Index_col)) {
comp.setBackground(Color.gray);
} else if (Index_row % 2 == 0) {
comp.setBackground(new Color(237, 243, 255));
} else {
comp.setBackground(Color.white);
}
return comp;
}
};
// set up editor that makes sure only doubles are accepted as entry
// and only the Date column is editable.
m_table.setDefaultEditor(Object.class, new TableCellEditor() {
JTextField m_textField = new JTextField();
int m_iRow, m_iCol;
@Override
public boolean stopCellEditing() {
m_table.removeEditor();
String text = m_textField.getText();
// Log.warning.println(text);
m_model.setValueAt(text, m_iRow, m_iCol);
// try {
// Double.parseDouble(text);
// } catch (Exception e) {
// return false;
// }
modelToTaxonset();
return true;
}
@Override
public boolean isCellEditable(EventObject anEvent) {
return m_table.getSelectedColumn() == 1;
}
@Override
public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int rowNr, int colNr) {
if (!isSelected) {
return null;
}
m_iRow = rowNr;
m_iCol = colNr;
m_textField.setText((String) value);
return m_textField;
}
@Override
public boolean shouldSelectCell(EventObject anEvent) {
return false;
}
@Override
public void removeCellEditorListener(CellEditorListener l) {
}
@Override
public Object getCellEditorValue() {
return null;
}
@Override
public void cancelCellEditing() {
}
@Override
public void addCellEditorListener(CellEditorListener l) {
}
});
m_table.putClientProperty("terminateEditOnFocusLost", Boolean.TRUE);
m_table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
int size = m_table.getFont().getSize();
m_table.setRowHeight(20 * size / 13);
m_table.getColumnModel().getColumn(0).setPreferredWidth(250 * size / 13);
m_table.getColumnModel().getColumn(1).setPreferredWidth(250 * size / 13);
JTableHeader header = m_table.getTableHeader();
header.addMouseListener(new ColumnHeaderListener());
JScrollPane pane = new JScrollPane(m_table);
Box tableBox = Box.createHorizontalBox();
tableBox.add(Box.createHorizontalGlue());
tableBox.add(pane);
tableBox.add(Box.createHorizontalGlue());
Box box = Box.createVerticalBox();
box.add(createFilterBox());
box.add(tableBox);
box.add(createButtonBox());
return box;
}
use of javax.swing.table.JTableHeader in project netbeans-rcp-lite by outersky.
the class ETableColumn method resize.
/**
* Forces the table to resize given column.
*/
private void resize(int newWidth, JTable table) {
int oldWidth = getWidth();
JTableHeader header = table.getTableHeader();
if (header == null) {
return;
}
header.setResizingColumn(this);
final int oldMin = getMinWidth();
final int oldMax = getMaxWidth();
setMinWidth(newWidth);
setMaxWidth(newWidth);
setWidth(newWidth);
// The trick is to restore the original values
// after the table has be layouted. During layout this column
// has fixed width (by setting min==max==preffered)
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
setMinWidth(oldMin);
setMaxWidth(oldMax);
}
});
Container container;
if ((header.getParent() == null) || ((container = header.getParent().getParent()) == null) || !(container instanceof JScrollPane)) {
header.setResizingColumn(null);
return;
}
if (!container.getComponentOrientation().isLeftToRight() && !header.getComponentOrientation().isLeftToRight()) {
if (table != null) {
JViewport viewport = ((JScrollPane) container).getViewport();
int viewportWidth = viewport.getWidth();
int diff = newWidth - oldWidth;
int newHeaderWidth = table.getWidth() + diff;
/* Resize a table */
Dimension tableSize = table.getSize();
tableSize.width += diff;
table.setSize(tableSize);
/* If this table is in AUTO_RESIZE_OFF mode and
* has a horizontal scrollbar, we need to update
* a view's position.
*/
if ((newHeaderWidth >= viewportWidth) && (table.getAutoResizeMode() == JTable.AUTO_RESIZE_OFF)) {
Point p = viewport.getViewPosition();
p.x = Math.max(0, Math.min(newHeaderWidth - viewportWidth, p.x + diff));
viewport.setViewPosition(p);
}
}
}
header.setResizingColumn(null);
}
use of javax.swing.table.JTableHeader in project netbeans-rcp-lite by outersky.
the class TreeTable method configureEnclosingScrollPane.
/**
* Overridden - JTable's implementation of the method will
* actually attach (and leave behind) a gratuitous border
* on the enclosing scroll pane.
*/
@Override
protected final void configureEnclosingScrollPane() {
Container p = getParent();
if (p instanceof JViewport) {
Container gp = p.getParent();
if (gp instanceof JScrollPane) {
JScrollPane scrollPane = (JScrollPane) gp;
JViewport viewport = scrollPane.getViewport();
if ((viewport == null) || (viewport.getView() != this)) {
return;
}
JTableHeader jth = getTableHeader();
if (jth != null) {
jth.setBorder(null);
}
scrollPane.setColumnHeaderView(jth);
}
}
}
use of javax.swing.table.JTableHeader in project VideoOptimzer by attdevsupport.
the class CheckBoxHeader method handleClickEvent.
/**
* for handling mouse events
* @param e
*/
protected void handleClickEvent(MouseEvent e) {
if (mousePressed) {
mousePressed = false;
JTableHeader header = (JTableHeader) (e.getSource());
JTable tableView = header.getTable();
TableColumnModel columnModel = tableView.getColumnModel();
int viewColumn = columnModel.getColumnIndexAtX(e.getX());
int column = tableView.convertColumnIndexToModel(viewColumn);
if (viewColumn == this.column && e.getClickCount() == 1 && column != -1) {
doClick();
}
}
}
Aggregations