0

Tell me how to make automatic scrolling JPanel?

JScrollBar sb = scroll.getVerticalScrollBar();
    scroll.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
    testPanel.setLayout(new BoxLayout(testPanel, BoxLayout.Y_AXIS));
    scroll.getViewport().add(testPanel);
    scroll.getViewport().setAutoscrolls(true);
    button.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            testPanel.add(new JLabel("<html><img  height='80' width='100' src='https://developer.cdn.mozilla.net/media/img/mdn-logo-sm.png' /></html>"));
            testPanel.updateUI();
            sb.setValue(sb.getMaximum());
        }
    });

Everything seems to be working, but the scrolling is not working to the end, a picture is not in line of sight.

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
Elsrix
  • 3
  • 1
  • 2
    [JComponent#scrollRectToVisible](http://docs.oracle.com/javase/7/docs/api/javax/swing/JComponent.html#scrollRectToVisible(java.awt.Rectangle)) – MadProgrammer Mar 14 '15 at 07:00
  • Thank U! Prompt please, that's still a question. How to make was transferred to a new line if the text extends beyond the borders? – Elsrix Mar 14 '15 at 09:29
  • Please edit your question to include a [complete example](http://stackoverflow.com/help/mcve) that shows your current approach; `updateUI()` is not appropriate in this context; see also this [example](http://stackoverflow.com/a/7203419/230513). – trashgod Mar 14 '15 at 10:50

0 Answers0