0

I've been searching for an answer, but everything else comes very close, but isn't the problem I'm having.

So my main class creates a new JFrame, adds a panel as the content panel, and I add a scrollpanel to that content panel.

Now I create some of my extending JPanel classes, add them to the scroll pane and see nothing but an empty frame.

And I have checked to make sure there is indeed a list of FTPFile's

Here is the main code:

public browser(ftpHandler _FTP) {

    FTP = _FTP;
    Panels = new ArrayList<JPanel>();

    frame = new JFrame("File Browser");
    frame.setContentPane(mainPanel);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setPreferredSize(new Dimension(750, 500));
    frame.setSize(frame.getPreferredSize());
    frame.setMinimumSize(frame.getSize());

    mainPanel.setLayout(new FlowLayout(FlowLayout.LEFT));

    listFiles();

    frame.pack();
    frame.setVisible(true);
}

public void listFiles(){
    Panels.clear();
    FTPFile[] list = null;
    try {
        list = FTP.listFiles();
    } catch (Exception e) {
        e.printStackTrace();
    }

    for(FTPFile file : list){
        fileObject FO = new fileObject(file);
        Panels.add(FO);
        scrollPane.add(FO);
    }

    scrollPane.updateUI();
}

And my extended JPanel, fileObject

public class fileObject extends JPanel {
private FTPFile file;
private JLabel Label;
private ImageIcon Icon;
private int FileType;
private final int IconSize = 25;
private final Dimension panelSize = new Dimension(150, 40);

public fileObject(FTPFile FILE){
    file = FILE;
    FileType = file.getType();
    this.setSize(panelSize);
    this.setPreferredSize(panelSize);
    this.setMinimumSize(panelSize);
    this.setLayout(new WrapLayout());

    switch (FileType){
        case FTPFile.TYPE_DIRECTORY:
            Icon = resizeImage(new ImageIcon(getClass().getResource("/com/taylor/48px/folder.png")),IconSize);
            break;
        case FTPFile.TYPE_FILE:
            try {
                String FileExtension = file.getName().substring(file.getName().lastIndexOf(".")+1);
                Icon = resizeImage(new ImageIcon(getClass().getResource("/com/taylor/48px/"+FileExtension+".png")),IconSize);
            } catch(Exception e) {
                Icon = resizeImage(new ImageIcon(getClass().getResource("/com/taylor/48px/_blank.png")),IconSize);
            }
            break;
        case FTPFile.TYPE_LINK:
            Icon = resizeImage(new ImageIcon(getClass().getResource("/com/taylor/48px/_page.png")),IconSize);
            break;
    }
    Label = new JLabel(file.getName(), Icon, JLabel.LEFT);
    this.add(Label);

}

private ImageIcon resizeImage(ImageIcon II, int Size){
    Image img = II.getImage();
    BufferedImage resizedImage = new BufferedImage(Size, Size, BufferedImage.TYPE_INT_ARGB);
    Graphics2D g2 = resizedImage.createGraphics();
    g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
    g2.drawImage(img, 0, 0, Size, Size, null);
    g2.dispose();
    return new ImageIcon(resizedImage);
}
}
Tazmanian Tad
  • 193
  • 1
  • 2
  • 12
  • 2
    1) For better help sooner, post an [MCVE](http://stackoverflow.com/help/mcve) (Minimal Complete Verifiable Example) or [SSCCE](http://www.sscce.org/) (Short, Self Contained, Correct Example). 2) One way to get images for an example, is to hot link to images seen in [this Q&A](http://stackoverflow.com/q/19209650/418556). 3) See [Should I avoid the use of set(Preferred|Maximum|Minimum)Size methods in Java Swing?](http://stackoverflow.com/q/7229226/418556) (Yes.) – Andrew Thompson Dec 03 '14 at 10:55
  • 5
    .. 4) Please learn common Java nomenclature (naming conventions - e.g. `EachWordUpperCaseClass`, `firstWordLowerCaseMethod()`, `firstWordLowerCaseAttribute` unless it is a `CONSTANT`) and use it consistently. – Andrew Thompson Dec 03 '14 at 10:56
  • Added the github source code link, and updated the variable/method names that you spoke of. Still seeking an answer – Tazmanian Tad Dec 03 '14 at 22:03

1 Answers1

0

I got this working, it turns out I was had my panels set up wrong, they were setup like this:

JFrame

--mainPanel

----scrollPane

And I was adding my extended panel to the scrollPane

And this seemed to not work, so I added another panel inside the scrollPane and started adding my extended panels to this new panel and it started working!

Tazmanian Tad
  • 193
  • 1
  • 2
  • 12