【问题标题】:ArrayList with images JAVA带有图像的 ArrayList JAVA
【发布时间】:2014-11-16 14:44:02
【问题描述】:

我有带有图像 url 的数组列表。然后我正在创建图像,但滚动面板中只显示一个。

这是我的代码:

try{
    for (int i = 0; i < arrayName.size(); i++) {
        String url2 = arrayName.get(i);
        JLabel picLabel = new JLabel(new ImageIcon(new URL(url2)));
        picLabel.setSize(100,100);
        scrollPane.add(picLabel);
        lol.add( scrollPane);
        System.out.println(url2);
    }
} catch (MalformedURLException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}

谁能帮帮我?

【问题讨论】:

    标签: java image url arraylist


    【解决方案1】:

    JScrollPane 有一个 JComponent 作为视口。您应该将组件添加到视口视图,而不是直接添加到 JScrollPane。因此它由 JScrollBars、header、JViewport 等组成。

    滚动的“东西”是设置为视口的JComponent。

    因此,您必须将包含所有图像的视图设置为 JScrollPane 的视口,它应该可以工作。请参阅JScrollPanel JavaDoc 了解更多信息。

    【讨论】:

      【解决方案2】:
      JPanel imagePanel = new JPanel();
      imagePanel.setLayout(new FlowLayout());
      scrollPanel = new JscrollPane(imagePanel);
      try{
          for (int i = 0; i < arrayName.size(); i++) {
              String url2 = arrayName.get(i);
              JLabel picLabel = new JLabel(new ImageIcon(new URL(url2)));
              picLabel.setSize(100,100);
              imagePanel.add(picLabel);
              System.out.println(url2);
          }
      lol.add( scrollPane);
      } catch (MalformedURLException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2014-04-28
        • 1970-01-01
        • 2012-10-09
        • 2016-10-02
        • 2012-03-25
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多