0
   JScrollBar _horizontalScroll;
  _verticalScroll = new JScrollBar(JScrollBar.VERTICAL);
   this.add(_verticalScroll);
   _verticalScroll.addAdjustmentListener(this);
   _verticalScroll.setVisible(true);
   _horizontalScroll = new JScrollBar(JScrollBar.HORIZONTAL);
   _horizontalScroll.addAdjustmentListener(this);
   _horizontalScroll.setVisible(true);

I have a code shown above, here vertical scroll bar is working fine, but horizontal scroll bar is not working (doesn't appear on my Swing GUI).

mKorbel
  • 109,525
  • 20
  • 134
  • 319
vibhor
  • 109
  • 4
  • 14

2 Answers2

2

Try adding the entire panel into the JScrollPane.

JScrollPane scrollPane = new JScrollPane(panel,
                     ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, 
                     ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);

And you can add your listeners using

scrollPane.getHorizontalScrollBar().addAdjustmentListener(this);
Harry Joy
  • 58,650
  • 30
  • 162
  • 207
Suken Shah
  • 1,622
  • 14
  • 20
2

You never add your horizontal scrollbar.

Jeffrey
  • 44,417
  • 8
  • 90
  • 141