开发者

Horizontal scroll bar doesn't show up?

开发者 https://www.devze.com 2023-03-20 06:33 出处:网络
JScrollBar _hor开发者_运维问答izontalScroll; _verticalScroll = new JScrollBar(JScrollBar.VERTICAL);
   JScrollBar _hor开发者_运维问答izontalScroll;
  _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).


You never add your horizontal scrollbar.


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);
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号