Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/371.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 自动滚动JPanel_Java_Swing_Jscrollpane - Fatal编程技术网

Java 自动滚动JPanel

Java 自动滚动JPanel,java,swing,jscrollpane,Java,Swing,Jscrollpane,告诉我如何进行自动滚动JPanel JScrollBar sb = scroll.getVerticalScrollBar(); scroll.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS); testPanel.setLayout(new BoxLayout(testPanel, BoxLayout.Y_AXIS)); scroll.getViewport().add(t

告诉我如何进行自动滚动
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());
        }
    });
JScrollBar sb=scroll.getVerticalScrollBar();
scroll.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL\u SCROLLBAR\u ALWAYS);
testPanel.setLayout(新的BoxLayout(testPanel,BoxLayout.Y_轴));
scroll.getViewport().add(testPanel);
scroll.getViewport().setAutoscrolls(true);
addActionListener(新建ActionListener()){
@凌驾
已执行的公共无效操作(操作事件e){
testPanel.add(新的JLabel(“”);
testPanel.updateUI();
sb.setValue(sb.getMaximum());
}
});

一切似乎都正常,但滚动到最后都不正常,图片不在视线范围内。

谢谢!请提示,这还是个问题。如果文本超出了边界,如何将其转换为新行?请编辑您的问题,以包括显示您当前方法的
updateUI()
在这种情况下不合适;另见此。