本人刚学习java,刚刚完成了一个翻转棋小游戏,当中间一个问题不知怎么解决!
    我用JList来显示下棋的步骤(外加JScrollPane)如A1,B2等。但随着下棋的步骤增多,如何能让滚动条自动滚动,让当前下的步骤始终显示出来,恳请各位高手指教!

解决方案 »

  1.   

    可以考虑每显示一行就调用setCaretPosition()方法,参数么,用Document下的getLength()得到总长,就能把光标设到结尾处,于是就跟上你的显示了
      

  2.   

    JScrollBar bar = new JScrollBar();
    JScrollPane jsp = new JScrollPane();
    jsp.setVerticalScrollBar(bar);
    bar.setValue(bar.getMaximum());
      

  3.   

    public void ensureIndexIsVisible(int index)
    Scrolls the viewport to make the specified cell completely visible. Note, for this method to work, the JList must be displayed within a JViewport. Parameters:
    index - the index of the cell to make visible
      

  4.   

    感谢各位的关注,jviewport怎么用啊!