This site requires JavaScript, please enable it in your browser!
Greenfoot back
davidlewine
davidlewine wrote ...

2011/3/30

scroll bar in executable jar

davidlewine davidlewine

2011/3/30

#
I would like to create a world that is longer than the screen height, and would like to scroll using a scroll bar when I open the executable jar file. I know I could make my own scroll bar out of Greenfoot actors which would work together with a scrollable world (moving the scroll bar level indicator actor would reposition all objects in the world) but I would rather just have the world be in a scrollable window like it is when I open a project in the greenfoot application. Could it be as simple as finding the right Jpanel in the code and making it scrollable? Any advice or hints about where to look in the greenfoot code would be appreciated.
MathManiac MathManiac

2011/4/2

#
import javax.swing.*;
import java.awt.*;

public class HelloWorld extends JFrame {
    
    public HelloWorld() {
        setSize(640, 430);
        MyPane p = new MyPane();
        add(new JScrollBar(p));
        setVisible(true);
        //Following line optional. Closes whole program (Even Greenfoot App itself) when red X clicked
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }
    
    private class MyPane extends JPanel {
        
        public void paint(Graphics g) {
            
            //Mess around here        
        }
        
    }
}
I have an idea, but it has to be in a JFrame, so it's harder to do sprites. Here's the basic code:
davmac davmac

2011/4/4

#
davidlewine, look at the greenfoot.export.GreenfootScenarioViewer class. You might turn the center panel into a JScrollPane for instance. MathManiac: I think the question is about Greenfoot's own code, not about how to create a scroll bar generally.
You need to login to post a reply.