From 7a88a4afa153f444629d3fa49b025a8a146b5295 Mon Sep 17 00:00:00 2001 From: Stephan Schwär Date: Mon, 30 Nov 2020 14:27:37 +0900 Subject: [client] Make table background use look and feel The table was opaque and therefore did not adhere to the look and feel. Table and TableCellRenderer now set to non opaque for non selected rows which lets the background through. Selected rows still should be opaque to show a different background indicating selection (e.g. blue). --- .../dozmod/gui/control/table/ListTable.java | 36 ++++++++++++---------- 1 file changed, 20 insertions(+), 16 deletions(-) (limited to 'dozentenmodul/src/main/java') diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/table/ListTable.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/table/ListTable.java index cd1ed7b5..8ac6441d 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/table/ListTable.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/table/ListTable.java @@ -1,7 +1,6 @@ package org.openslx.dozmod.gui.control.table; import java.awt.Component; -import java.awt.Font; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; @@ -74,7 +73,8 @@ public abstract class ListTable extends JTable { this.setRowSelectionAllowed(true); this.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); this.setRowHeight(this.getRowHeight() * Config.getFontScaling() / 100); - + this.setOpaque(false); + sorter.addRowSorterListener(new RowSorterListener() { @Override public void sorterChanged(RowSorterEvent e) { @@ -105,14 +105,14 @@ public abstract class ListTable extends JTable { } return itemList; } - + public T getSelectedItem() { int rowIndex = getSelectedRow(); if (rowIndex == -1) return null; return getViewRow(rowIndex); } - + public List getData() { if (model.data == null) return null; @@ -196,11 +196,11 @@ public abstract class ListTable extends JTable { * Called when rendering a column is being prepared. This is a good time to * change the color or font for the given cell. * - * @param component The component representing the cell being rendered - * @param row item of the row being rendered + * @param component The component representing the cell being rendered + * @param row item of the row being rendered * @param listTableColumn column (model-based) of the cell being rendered - * @param isSelected whether the row is currently selected - * @return + * @param isSelected whether the row is currently selected + * @return */ public Component prepareRenderHook(Component component, T row, ListTableColumn listTableColumn, boolean isSelected) { @@ -213,7 +213,7 @@ public abstract class ListTable extends JTable { * displayable item. By default this is the identity function, returning the * value as-is. * - * @param value Value to render + * @param value Value to render * @param column Column index (model-based) being rendered * @return Rendered version of value. This should match the column class */ @@ -226,7 +226,8 @@ public abstract class ListTable extends JTable { Component c = super.prepareRenderer(renderer, row, column); T item = getViewRow(row); if (c != null && item != null) { - c = prepareRenderHook(c, item, model.getColumn(convertColumnIndexToModel(column)), isRowSelected(row)); + c = prepareRenderHook(c, item, model.getColumn(convertColumnIndexToModel(column)), + isRowSelected(row)); } return c; } @@ -279,12 +280,12 @@ public abstract class ListTable extends JTable { break; } } - + @Override public boolean isCellEditable(int row, int col) { return columns[col].column.isEditable; } - + @Override public void setValueAt(Object aValue, int row, int col) { if (isCellEditable(row, col)) { @@ -323,7 +324,7 @@ public abstract class ListTable extends JTable { return null; return table.getValueAtInternal(item, columns[columnIndex].column); } - + public T getModelRow(int rowIndex) { return table.getModelRow(rowIndex); } @@ -358,6 +359,8 @@ public abstract class ListTable extends JTable { value = modelValueToDisplayFormat(value, model.getColumn(convertColumnIndexToModel(column))); } super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); + // If selected the row should be opaque. Otherwise the selection background is not shown. + setOpaque(isSelected); setBorder(null); return this; } @@ -371,7 +374,7 @@ public abstract class ListTable extends JTable { if (value != null) { value = modelValueToDisplayFormat(value, model.getColumn(convertColumnIndexToModel(column))); } - setIcon((Icon)value); + setIcon((Icon) value); return this; } } @@ -393,8 +396,9 @@ public abstract class ListTable extends JTable { public ListTableColumn(String colName, Class colClass, Comparator sortComparator) { this(colName, colClass, sortComparator, false); } - - public ListTableColumn(String colName, Class colClass, Comparator sortComparator, boolean isEditable) { + + public ListTableColumn(String colName, Class colClass, Comparator sortComparator, + boolean isEditable) { this.isEditable = isEditable; this.colName = colName; this.colClass = colClass; -- cgit v1.2.3-55-g7522