Note that there are some explanatory texts on larger screens.

plurals
  1. POMultiple views in a JViewport?
    text
    copied!<p>Currently I have a nifty JViewport with a Jlabel set up and used as a view. I'm wondering if it's possible to use layered Jlabels as the Viewport's view. IE: I want to add new JLabels into a pre-existing Viewport.</p> <p>Thanks!</p> <p>EDIT: On StanislavL's advice, I'm now using a JLayeredPane within an JScrollPane. Currently there are two JLabels in the JLayeredPane, when I scroll the JScrollPane, the larger background image scrolls properly, by the smaller shipSprite remains in the same position. Any ideas how I can get them to scroll together?</p> <pre><code>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()); } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload