/*
   *  This method is called every time:
   *  - to make sure the viewport is returned to its default position
   *  - to remove the horizontal scrollbar when it is not wanted
   */
  private void checkHorizontalScrollBar(BasicComboPopup popup) {
    //  Reset the viewport to the left

    JViewport viewport = scrollPane.getViewport();
    Point p = viewport.getViewPosition();
    p.x = 0;
    viewport.setViewPosition(p);

    //  Remove the scrollbar so it is never painted

    if (!scrollBarRequired) {
      scrollPane.setHorizontalScrollBar(null);
      return;
    }

    //	Make sure a horizontal scrollbar exists in the scrollpane

    JScrollBar horizontal = scrollPane.getHorizontalScrollBar();

    if (horizontal == null) {
      horizontal = new JScrollBar(JScrollBar.HORIZONTAL);
      scrollPane.setHorizontalScrollBar(horizontal);
      scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    }

    //	Potentially increase height of scroll pane to display the scrollbar

    if (horizontalScrollBarWillBeVisible(popup, scrollPane)) {
      Dimension scrollPaneSize = scrollPane.getPreferredSize();
      scrollPaneSize.height += horizontal.getPreferredSize().height;
      scrollPane.setPreferredSize(scrollPaneSize);
      scrollPane.setMaximumSize(scrollPaneSize);
      scrollPane.revalidate();
    }
  }
Example #2
0
  public void setResultSet(DiskResultSet rset) throws Exception {
    set = rset;

    max = rset.getRowCount();

    table.setModel(model);
    table.setModel(this);

    offset = 0;
    scrollBar.setValue(0);
    scrollBar.setMaximum((max < window ? 0 : max - window));
  }
Example #3
0
  private void addControls() {
    setLayout(new BorderLayout());

    scrollBar = new JScrollBar(JScrollBar.VERTICAL);

    table = new JTable(this);
    add(
        new JScrollPane(
            table,
            JScrollPane.VERTICAL_SCROLLBAR_NEVER,
            JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED));
    add(scrollBar, BorderLayout.EAST);

    scrollBar.addAdjustmentListener(this);
    scrollBar.setMinimum(0);
  }
Example #4
0
 public void adjustmentValueChanged(AdjustmentEvent e) {
   offset = scrollBar.getValue();
   table.tableChanged(cEvent);
 }
Example #5
0
 public void clear() {
   table.setModel(model);
   offset = 0;
   scrollBar.setValue(0);
   scrollBar.setMaximum(0);
 }
  /*
   *  I can't find any property on the scrollBar to determine if it will be
   *  displayed or not so use brute force to determine this.
   */
  protected int getScrollBarWidth(BasicComboPopup popup, JScrollPane scrollPane) {
    int scrollBarWidth = 0;
    JComboBox comboBox = (JComboBox) popup.getInvoker();

    if (comboBox.getItemCount() > comboBox.getMaximumRowCount()) {
      JScrollBar vertical = scrollPane.getVerticalScrollBar();
      scrollBarWidth = vertical.getPreferredSize().width;
    }

    return scrollBarWidth;
  }