コード例 #1
0
    @Override
    public Dimension getPreferredSize() {
      if (scrollable == null) {
        return super.getPreferredSize();
      } else {
        int width = super.getPreferredSize().width;
        int height = ((JComponent) scrollable).getPreferredSize().height;

        // the list view has some weird rendering sometimes (double space after last result)
        // so don't fill full screen on list view
        if ((scrollable instanceof ListViewTable)) {
          // old check, if sponsored results aren't showing properlly revert to just using this
          if (sponsoredResultsPanel.isVisible()) {
            height = Math.max(height, sponsoredResultsPanel.getPreferredSize().height);
          }
        } else { // classic view
          int headerHeight = 0;

          // the table headers aren't being set on the scrollpane, so if its visible check its
          // height and subtract it from the viewport size
          JTableHeader header = ((JTable) scrollable).getTableHeader();
          if (header != null && header.isShowing()) {
            headerHeight = header.getHeight();
          }

          // if the height of table is less than the scrollPane height, set preferred height
          // to same size as scrollPane
          if (height < scrollPane.getSize().height - headerHeight) {
            height = scrollPane.getSize().height - headerHeight;
          }
        }
        return new Dimension(width, height);
      }
    }
コード例 #2
0
  /** Part of print code coped from Sun */
  public void getPageInfo(Graphics g, PageFormat pageFormat) {

    subTableSplit = null;
    subTableSplitSize = 0;
    subPageIndex = 0;
    prevPageIndex = 0;

    fontHeight = (int) (g.getFontMetrics().getHeight() * scale);
    fontDesent = (int) (g.getFontMetrics().getDescent() * scale);

    tableHeader = _table.getTableHeader();
    //		double headerWidth = tableHeader.getWidth() * scale;
    headerHeight = tableHeader.getHeight() + _table.getRowMargin() * scale;

    pageHeight = pageFormat.getImageableHeight();
    pageWidth = pageFormat.getImageableWidth();

    //		double tableWidth =_table.getColumnModel().getTotalColumnWidth() * scale;
    tableHeight = _table.getHeight() * scale;
    rowHeight = _table.getRowHeight() + _table.getRowMargin() * scale;

    tableHeightOnFullPage = (int) (pageHeight - headerHeight - fontHeight * 2);
    tableHeightOnFullPage = tableHeightOnFullPage / rowHeight * rowHeight;

    TableColumnModel tableColumnModel = tableHeader.getColumnModel();
    int columns = tableColumnModel.getColumnCount();
    int columnMargin = (int) (tableColumnModel.getColumnMargin() * scale);

    int[] temp = new int[columns];
    int columnIndex = 0;
    temp[0] = 0;
    int columnWidth;
    int length = 0;
    subTableSplitSize = 0;
    while (columnIndex < columns) {

      columnWidth = (int) (tableColumnModel.getColumn(columnIndex).getWidth() * scale);

      if (length + columnWidth + columnMargin > pageWidth) {
        temp[subTableSplitSize + 1] = temp[subTableSplitSize] + length;
        length = columnWidth;
        subTableSplitSize++;
      } else {
        length += columnWidth + columnMargin;
      }
      columnIndex++;
    } // while

    if (length > 0) { // if are more columns left, part page
      temp[subTableSplitSize + 1] = temp[subTableSplitSize] + length;
      subTableSplitSize++;
    }

    subTableSplitSize++;
    subTableSplit = new int[subTableSplitSize];
    for (int i = 0; i < subTableSplitSize; i++) {
      subTableSplit[i] = temp[i];
    }
    totalNumPages = (int) (tableHeight / tableHeightOnFullPage);
    if (tableHeight % tableHeightOnFullPage >= rowHeight) { // at least 1 more row left
      totalNumPages++;
    }

    totalNumPages *= (subTableSplitSize - 1);
    pageinfoCalculated = true;
  }