Java分页Arraylist对象的下一个上一个按钮

时间:2013-02-03 21:28:55

标签: java arraylist pagination

我尝试为每个arraylist对象的5个项目添加next和prev按钮,但我无法解决它。 使用for循环,我为arraylist中的每个项目创建一个自己的面板。现在我想将视图限制为5个项目并添加上一个和下一个按钮。

public TabPanel(String name, MainPanel mainPanel) throws IOException {
    this.mainPanel = mainPanel;
    this.setName(name);
    this.data = new Data();
    setLayout(new BorderLayout());

    if (name.equals("EVENT LIST")) {
        productList = data.getAllProducts();
    } else {
        productList = data.getWishList();
    }
    JPanel eventPanel = new JPanel();
    eventPanel.setPreferredSize(new Dimension(500, 300));
    eventPanel.setLayout(new GridLayout(5, 1));

    for (Product product : productList) {    
        ProductPanel productPanel = new ProductPanel(product, this);
        eventPanel.add(productPanel);
    }
    add(eventPanel,BorderLayout.CENTER);


    /* Navigation Panel */
    ContentLabel = new JLabel(getPageContent());
    JPanel navigationPanel = new JPanel();
    next = new JButton("Next\u22b3");
    next.addActionListener(new NavigationListener());
    prev = new JButton("\u22b2Prev");
    prev.addActionListener(new NavigationListener());
    navigationPanel.add(prev);
    navigationPanel.add(next);

0 个答案:

没有答案