コード例 #1
0
  /** TableCellRenderer implementation */
  public Component getTableCellRendererComponent(
      JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
    // Try to set default fore- and background colors
    if (table != null) {
      JTableHeader header = table.getTableHeader();
      if (header != null) {
        setForeground(header.getForeground());
        setBackground(header.getBackground());
        setFont(header.getFont());
        AbstractTableModel model = (AbstractTableModel) table.getModel();

        column = table.convertColumnIndexToModel(column);
        setText(model.getColumnName(column));
        // set normal border
        setBorder(javax.swing.UIManager.getBorder("TableHeader.cellBorder"));

        if (m_sortmode == SortMode.ASCENDING) setIcon(m_upimage);
        else if (m_sortmode == SortMode.DESCENDING) setIcon(m_downimage);
        else
          // if NONE
          setIcon(m_emptyheaderimage);
      }
    }
    return this;
  }
コード例 #2
0
ファイル: LibraryApp.java プロジェクト: smarr/AmbientTalk-lib
    public Component getTableCellRendererComponent(
        JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
      super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);

      // Inherit the colors and font from the header component
      if (bookTable_ != null) {
        JTableHeader header = bookTable_.getTableHeader();
        if (header != null) {
          setForeground(header.getForeground());
          setBackground(header.getBackground());
          setFont(header.getFont());
        }
      }

      if (value instanceof JLabel) {
        setIcon(((JLabel) value).getIcon());
        setText(((JLabel) value).getText());
      } else {
        setText((value == null) ? "" : value.toString());
        setIcon(null);
      }
      setBorder(UIManager.getBorder("TableHeader.cellBorder"));
      setHorizontalAlignment(JLabel.CENTER);
      return this;
    }
コード例 #3
0
  public Component getTableCellRendererComponent(
      JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int col) {
    int index = -1;
    int direction = 0;

    if (table != null) {
      if (table.getModel() instanceof ISorterFilterTableModel) {
        ISorterFilterTableModel model = (ISorterFilterTableModel) table.getModel();
        index = table.convertColumnIndexToView(model.getSortColumn());
        direction = model.getSortDirection();
      }

      JTableHeader header = table.getTableHeader();
      if (header != null) {
        setForeground(header.getForeground());
        setBackground(header.getBackground());
        setFont(header.getFont());
      }
    }
    setIcon(
        col == index && direction != ISorterFilterTableModel.NONE
            ? new SortArrowIcon(direction)
            : null);
    setText((value == null) ? "" : value.toString());
    setBorder(UIManager.getBorder("TableHeader.cellBorder"));
    return this;
  }
コード例 #4
0
 /**
  * Constructs with the specified initial table
  *
  * @param table the instance of JTable
  */
 public RowHeaderTableCellRenderer(JTable table) {
   header = table.getTableHeader();
   setOpaque(true);
   setBorder(UIManager.getBorder("TableHeader.cellBorder"));
   // setHorizontalAlignment(CENTER);
   setForeground(header.getForeground());
   setBackground(header.getBackground());
   setFont(header.getFont());
 }
コード例 #5
0
 RowHeaderRenderer(JTable table) {
   JTableHeader header = table.getTableHeader();
   setOpaque(true);
   setBorder(BorderFactory.createLineBorder(Color.black));
   setHorizontalAlignment(LEFT);
   setForeground(header.getForeground());
   setBackground(header.getBackground());
   setFont(app.getPlainFont());
 }
コード例 #6
0
ファイル: CheckBoxHeader.java プロジェクト: srvarey/postion
 @Override
 public Component getTableCellRendererComponent(
     JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
   if (table != null) {
     JTableHeader header = table.getTableHeader();
     if (header != null) {
       setForeground(header.getForeground());
       setBackground(header.getBackground());
       setFont(header.getFont());
       header.addMouseListener(this);
     }
   }
   setColumn(column);
   setBorder(UIManager.getBorder("TableHeader.cellBorder"));
   return this;
 }
 @Override
 public Component getTableCellRendererComponent(
     JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
   if (table != null) {
     JTableHeader header = table.getTableHeader();
     if (header != null) {
       setForeground(header.getForeground());
       setBackground(header.getBackground());
       setFont(header.getFont());
     }
     setText(getText(value, row, column));
     setBorder(UIManager.getBorder("TableHeader.cellBorder"));
     setHorizontalAlignment(JLabel.CENTER);
   }
   return this;
 }
コード例 #8
0
    public Component getTableCellRendererComponent(
        JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
      if (table != null) {
        JTableHeader header = table.getTableHeader();

        if (header != null) {
          setForeground(header.getForeground());
          setBackground(header.getBackground());
          setFont(header.getFont());
        }
      }

      if (isSelected) {
        setFont(getFont().deriveFont(Font.BOLD));
      }

      setText((value == null) ? "" : value.toString());
      setBorder(UIManager.getBorder("TableHeader.cellBorder"));

      return this;
    }
コード例 #9
0
  /** Constructor */
  public HeaderRenderer(JTable table, boolean rowModel) {
    this.table = table;
    this.rowModel = rowModel;
    JTableHeader header = table.getTableHeader();
    this.selectedFont = header.getFont().deriveFont(Font.BOLD);
    this.unselectedFont = header.getFont();
    this.selectedFgColor = UIManager.getColor("textHighlightText");
    this.unselectedFgColor = header.getForeground();
    this.unselectedBgColor = header.getBackground().darker();

    Color c = table.getSelectionBackground();
    float[] hsb = Color.RGBtoHSB(c.getRed(), c.getGreen(), c.getBlue(), null);
    this.selectedBgColor = Color.getHSBColor(hsb[0], hsb[1] * 2f, hsb[2]);

    setOpaque(true);
    setBorder(BorderFactory.createEmptyBorder());
    setHorizontalAlignment(CENTER);
    setForeground(unselectedFgColor);
    setBackground(unselectedBgColor);
    setFont(unselectedFont);
    if (!rowModel) {
      setBorder(
          new AbstractBorder() {
            public Insets getBorderInsets(Component c) {
              return INSETS;
            }

            public Insets getBorderInsets(Component c, Insets insets) {
              return INSETS;
            }

            public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
              g.setColor(HeaderRenderer.this.table.getGridColor().darker());
              g.drawLine(x, y, x + width, y);
              g.drawLine(x, y, x, y + height);
            }
          });
    }
  }
コード例 #10
0
  public Component getTableCellRendererComponent(
      JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
    // Whether we are printing the result or not
    boolean isPaintingForPrint = false;

    // Title icon
    Icon sortIcon = null;
    if (table != null) {
      JTableHeader header = table.getTableHeader();
      if (header != null) {
        Color fgColor = null;
        Color bgColor = null;
        if (hasFocus) {
          fgColor = UIManager.getColor("TableHeader.focusCellForeground");
          bgColor = UIManager.getColor("TableHeader.focusCellBackground");
        }
        if (fgColor == null) {
          fgColor = header.getForeground();
        }
        if (bgColor == null) {
          bgColor = header.getBackground();
        }
        setForeground(fgColor);
        setBackground(bgColor);

        setFont(header.getFont());

        isPaintingForPrint = header.isPaintingForPrint();
      }

      if (!isPaintingForPrint && table.getRowSorter() != null) {
        if (!horizontalTextPositionSet) {
          // There is a row sorter, and the developer hasn't
          // set a text position, change to leading.
          setHorizontalTextPosition(JLabel.LEADING);
        }
        List<? extends RowSorter.SortKey> sortKeys = table.getRowSorter().getSortKeys();
        if (sortKeys.size() > 0
            && sortKeys.get(0).getColumn() == table.convertColumnIndexToModel(column)) {
          switch (sortKeys.get(0).getSortOrder()) {
            case ASCENDING:
              sortIcon = UIManager.getIcon("Table.ascendingSortIcon");
              break;
            case DESCENDING:
              sortIcon = UIManager.getIcon("Table.descendingSortIcon");
              break;
            case UNSORTED:
              sortIcon = UIManager.getIcon("Table.naturalSortIcon");
              break;
          }
        }
      }
    }
    setIcon(sortIcon);

    // Title text
    setText(value == null ? "" : value.toString());

    // Title margin
    setMargin(WebTableStyle.headerMargin);

    return this;
  }