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()
在这种情况下不合适;另见此。