Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

Hello I have a game where you can have a shop and buy stuff. when you press enter the shop stock menu opens. I want to be able to show all of the items available and I want to be able to scroll threw them all with a jscrollpane or jscrollbar. I don't know how I would approach this please help me and please don't take this question down mods and admins because tis will be very helpful for me. here is my code if you need to see it:

import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Image;
import java.util.ArrayList;

import javax.swing.ImageIcon;
import javax.swing.JScrollPane;

public class stock {
    static Image img;
    public static int money = 1000;

    public static ArrayList<item> item = new ArrayList<item>();
    public static JScrollPane j = new JScrollPane();
    public static void tick(){
        if(Keys.isPressed(Keys.ESCAPE)){
            options.stockopen = false;
        }

        for (int i = 0; i < item.toArray().length; i++) {
            item.get(i).tick();
        }

        item.add(new item(200,100,8,"Melon"));
        item.add(new item(200,150,2,"Bread"));
        item.add(new item(200,200,1,"Milk"));

    }

    public static void render(Graphics g){
        ImageIcon i2 = new ImageIcon("res/stockscreen.png");
        img = i2.getImage();
        g.drawImage(img,0,0, null);


        g.setColor(Color.yellow);
        g.setFont(new Font("italic", Font.BOLD, 20));
        g.drawString("€ "+money, 13, 30);

        for (int i = 0; i < item.toArray().length; i++) {
            item.get(i).render(g);
            //if (item.get(i).isrem) {

            //}
        }

    }

}
share|improve this question

closed as off-topic by bummzack, Anko, Kevin Reid, Seth Battin, MrCranky Mar 26 '14 at 12:59

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions about debugging a problem in your project must present a concise selection of code and context so as to allow a reader to diagnose the issue without needing to read all of your code or to engage in extensive back-and-forth dialog. For more information, see this meta thread." – bummzack, Anko, Kevin Reid, MrCranky
If this question can be reworded to fit the rules in the help center, please edit the question.

    
Begging is not an effective way to avoid having your question closed. Being specific and explaining what you have already tried is more effective. I'm voting to close right now, because a blanket "please tell me how to do this" makes for a bad question. If you can, edit your question to ask about a specific problem you have had implementing your scroll area. In the meantime: google.com/search?q=javax.swing.jscrollpane+example –  Seth Battin Mar 23 '14 at 22:53

1 Answer 1

You can pass the menu container into the JscrollPane when new JscrollPane(menuContainer) and add the JscrollPane object you create where you are adding your menu-container.

example
If you want a JPanel to be in a JFrame and have JScrollPane to scroll through, you can do so by.....

JFrame jf = new JFrame();
// some statements
JPanel jp = new JPanel();
// some statements
JScrollPane js = new JScrollPane(jp);
jf.add(jp);

something like this.. here jp will be like the menu-container.

share|improve this answer
    
I don't fully understand that –  user2957632 Mar 22 '14 at 17:24
    
what is a menu container –  user2957632 Mar 22 '14 at 17:59
1  
You must be having something to Contain your menus, that would be your menu container, its a term not an actual part. –  Ankur Kumawat Mar 22 '14 at 19:17

Not the answer you're looking for? Browse other questions tagged or ask your own question.