【发布时间】:2009-01-15 22:58:00
【问题描述】:
我正在使用 Java Swing 制作应用程序,但遇到了问题。我制作了一个选项卡式面板,它需要一个简单的面板和一个滚动面板。简单的面板工作正常,但在我的滚动面板中我只能看到滚动条,而不是视口,我的代码如下:
内容窗格
public class ContentPane extends JTabbedPane {
private InfoPanel ip;
ScrollPanel sp;
public InfoPanel getIp() {
return ip;
}
public ContentPane(GraphPanel gp) {
this.sp = new ScrollPanel(gp);
this.sp.setViewportView(gp);
this.addTab("Graph", this.sp);
this.ip = new InfoPanel(gp);
this.addTab("Info", ip);
}
}
滚动面板
public class ScrollPanel extends JScrollPane {
public ScrollPanel(GraphPanel gp){
this.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
this.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
this.repaint();
}
}
图形面板
public GraphPanel(StatusBar sb) {
this.sb = sb;
zoomLevel = 5;
sm = new Simulation();
mh = new MouseHandler(this, sm);
this.addMouseListener(mh);
this.setBackground(new Color(240, 165, 98));
this.repaint();
}
由于我没有收到任何错误或异常,所以我现在完全迷失了采取哪种方法。
【问题讨论】:
-
我可以补充一点,我在 GraphPanel 中有一个 MouseListener,它仍然在面板中注册我的鼠标点击,但那里仍然没有显示任何内容..
标签: java swing jscrollpane viewport