tho*_*ine 15 java swing scroll jpanel
如何使JPanel可滚动?当我将它添加到包含面板时,我实现了可滚动界面
tabbedPane.add("Editor", new JScrollPane(storeyEditor = new MNScrollablePanel()));
Run Code Online (Sandbox Code Playgroud)
什么都行不通
码:
public class MNScrollablePanel extends JPanel implements Scrollable {
public Dimension getPreferredScrollableViewportSize() {
return getPreferredSize();
}
public int getScrollableBlockIncrement(Rectangle visibleRect, int orientation, int direction) {
return 10;
}
public boolean getScrollableTracksViewportHeight() {
return false;
}
public boolean getScrollableTracksViewportWidth() {
return false;
}
public int getScrollableUnitIncrement(Rectangle visibleRect, int orientation, int direction) {
return 10;
}
}
Run Code Online (Sandbox Code Playgroud)
小智 23
它和我一起工作....
JPanel test = new JPanel();
test.setPreferredSize(new Dimension( 2000,2000));
JScrollPane scrollFrame = new JScrollPane(test);
test.setAutoscrolls(true);
scrollFrame.setPreferredSize(new Dimension( 800,300));
this.add(scrollFrame);
Run Code Online (Sandbox Code Playgroud)
你必须使用JScrollPane.然后打电话给setViewportview(Component);
您不必实现可滚动,JPanel已经可以滚动
| 归档时间: |
|
| 查看次数: |
47490 次 |
| 最近记录: |