문제

Java Swing으로 응용 프로그램을 작성하고 문제가 있습니다. 간단한 패널과 스크롤 패널을 보관 해야하는 탭 패널을 만들었습니다. 간단한 패널은 잘 작동하지만 스크롤 패널에서 스크롤 바만 볼 수 있지만 뷰포트는 아닙니다. 내 코드는 다음과 같습니다.

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

스크롤 패널

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

나는 오류 나 예외를 얻지 못하기 때문에 이제 Aproach가 취해야 할 완전히 잃어 버렸습니다.

도움이 되었습니까?

해결책

jscrollpane을 서브 클래스하지 않아야합니다. 필요하지 않습니다.

그러나 그렇게한다면 스크롤 페인에 구성 요소를 추가하는 것을 잊지 마십시오.

당신의 서브 클래스에서 당신은입니다 ~ 아니다 스크롤 창에 그래프 패널 추가. :

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

노력하다:

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

GraphPanel이 jcomponent 또는 jpanel을 확장하도록합니다

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top