Frage

Ich mache eine Anwendung mit Java Swing und ich habe ein Problem. Ich habe ein Tabbed Panel, das eine einfache Platte, und einen Scroll-Panel halten, muß gemacht. Die einfache Platte funktioniert gut, aber in meinem Scroll-Panel kann ich nur die Bildlaufleisten sehen, aber nicht das Ansichtsfenster, mein Code ist wie folgt:

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);
    }
}

Scroll

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();
}

Da ich keine Fehler oder Ausnahmen, ich bin jetzt völlig verloren, in der aproach zu nehmen.

War es hilfreich?

Lösung

Sie sollten nicht Unterklasse JScrollPane, es nicht notwendig ist.

Aber wenn Sie dies tun, vergessen Sie nicht, die Komponente auf die scrollpane hinzuzufügen.

In der Unterklasse Sie sind nicht Hinzufügen der GraphPanel auf das Bildlauffenster.

public class ScrollPanel extends JScrollPane {
    public ScrollPanel(GraphPanel gp){

         // ::::  HERE ::: you are not doing anything with gp 
         // like this.setViewPort( gp ) or something like that

        this.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
        this.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
        this.repaint();
    }
}

Versuchen:

public class ScrollPanel extends JScrollPane {
    public ScrollPanel(GraphPanel gp){
        super( gp );
        .... etc ...            

Und haben GraphPanel verlängern JComponent oder JPanel

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top