1
我正在用Java Swing做一個應用程序,我有一個問題。我製作了一個帶標籤的面板,它需要一個簡單的面板和一個滾動面板。簡單的面板工作正常,但在我的滾動面板,我只能看到滾動條,而不是視口,我的代碼如下:JScrollPane現在顯示它的視口
的contentPane
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);
}
}
ScrollPanel
public class ScrollPanel extends JScrollPane {
public ScrollPanel(GraphPanel gp){
this.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
this.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
this.repaint();
}
}
GraphPanel
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,它仍然在面板中註冊我的鼠標點擊,但仍然沒有顯示在那裏.. – utdiscant 2009-01-15 23:05:49
你可以發佈截圖嗎? – OscarRyz 2009-01-15 23:13:37