01: package org.swingml.component;
02:
03: import java.awt.*;
04:
05: import javax.swing.*;
06: import javax.swing.border.*;
07: import javax.swing.table.*;
08:
09: import org.swingml.*;
10: import org.swingml.model.*;
11: import org.swingml.model.TableColumnModel;
12:
13: /**
14: * @author Crosslogic
15: */
16: public class TableHeaderCellRenderer extends DefaultTableCellRenderer {
17:
18: public Component getTableCellRendererComponent(JTable table,
19: Object value, boolean isSelected, boolean hasFocus,
20: int row, int column) {
21: JTableModel model = (JTableModel) table.getModel();
22: TableColumnModel columnModel = (TableColumnModel) model
23: .getColumns().get(column);
24: LabelDecorator
25: .decorateLabel(this , columnModel, table.getFont());
26:
27: setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED));
28:
29: // Set alignment
30: int alignment = JLabel.LEFT;
31: if (columnModel.getAlignment()
32: .equalsIgnoreCase(Constants.RIGHT)) {
33: alignment = JLabel.RIGHT;
34: } else if (columnModel.getAlignment().equalsIgnoreCase(
35: Constants.CENTER)) {
36: alignment = JLabel.CENTER;
37: }
38: setHorizontalAlignment(alignment);
39:
40: setValue(value);
41: return this;
42: }
43: }
|