2012-02-27 4 views
1

현재 Jlabel을 설정하고보기로 사용하여 멋진 JViewport를 사용하고 있습니다. 뷰포트 뷰로 레이어 Jlabel을 사용할 수 있는지 궁금합니다. IE : 기존의 뷰포트에 새 JLabel을 추가하고 싶습니다.JViewport의 다중 뷰?

감사합니다.

편집 : StanislavL의 조언에 따라 JScrollPane에서 JLayeredPane을 사용하고 있습니다. 현재 JLayeredPane에는 두 개의 JLabel이 있습니다. JScrollPane을 스크롤하면 더 큰 배경 이미지가 제대로 스크롤됩니다. 더 작은 shipSprite가 같은 위치에 유지됩니다. 내가 어떻게 그들을 함께 스크롤 할 수있는 아이디어?

public void initViewport() { 
    explorePort = new JScrollPane(); 
    explorePort.setBounds(0, 0, retailWidth, retailHeight); 
    explorePort.setBackground(new Color(0, 100, 0)); 
    explorePort.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); 
    explorePort.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); 

    ImageIcon background = Main.global.imgScaler.scaleImage(new ImageIcon("images/blankgrid.jpg"), retailWidth*2, retailHeight*2); 
    JLabel backSplash = new JLabel(background); 
    backSplash.setBounds(0, 0, retailWidth*2, retailHeight*2); 

    ImageIcon shipIcon = Main.global.imgScaler.scaleImage(new ImageIcon("images/ship.png"), Main.global.nodeWidth, Main.global.nodeHeight); 
    JLabel shipSprite = new JLabel(shipIcon); 
    shipSprite.setBounds(100, 100, Main.global.nodeWidth, Main.global.nodeHeight); 

    Main.global.gamePanel.add(backSplash, 0); 

    explorePort.setViewportView(backSplash); 
    Main.global.gamePanel.add(shipSprite, 1); 
    Main.global.gamePanel.add(explorePort, 2); 

    //explorePort.addMouseListener(this); 
    Main.global.gameFrame.addKeyListener(new ListenKey()); 
} 
+1

컨테이너를 컨테이너에 여러 lables를 추가 배치 할 [SSCCE] (http://sscce.org/) 그렇지 않으면 JLayeredPane 또는 JLayer를 수락해야합니다 .... (@stas) +1 – mKorbel

답변

관련 문제