Exemple #1
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);
  }
  private JScrollBar createScrollBar(int row) {
    JScrollBar scrollBar = new JScrollBar();
    scrollBar.setMinimum(0);
    scrollBar.setVisibleAmount(1);
    scrollBar.setBlockIncrement(1);
    scrollBar.setOrientation(JScrollBar.HORIZONTAL);

    GridBagConstraints scrollBarContraints = new GridBagConstraints();
    scrollBarContraints.fill = GridBagConstraints.HORIZONTAL;
    scrollBarContraints.weightx = 1.0;
    scrollBarContraints.gridx = 1;
    scrollBarContraints.gridy = row;
    super.add(scrollBar, scrollBarContraints);

    return scrollBar;
  }
    public void afterPanelsAdded() {
      myLeftScroll.setMinimum(0);
      myLeftScroll.setMaximum(myMaxColumnsLeft);
      myLeftScroll.addAdjustmentListener(
          new AdjustmentListener() {
            @Override
            public void adjustmentValueChanged(AdjustmentEvent e) {
              myInScrolling = true;

              final int scrollPosCorrected = myLeftScroll.getValue() + 1;
              if (myByLeft) {
                scrollMain(myLeftScroll.getValue(), myLeftModels);
                scrollOther(scrollPosCorrected, myMaxColumnsLeft, myMaxColumnsRight, myRightModels);
              } else {
                scrollMain(myLeftScroll.getValue(), myRightModels);
                scrollOther(scrollPosCorrected, myMaxColumnsRight, myMaxColumnsLeft, myLeftModels);
              }
              myInScrolling = false;
            }
          });
    }