The code is as such:
public static class Fileslist extends JFrame
{
List<Container> folderbuttons= new ArrayList<Container>();
List<JButton> folderbuttons2= new ArrayList<JButton>();
List<DbxEntry> filesandfolders=new ArrayList<DbxEntry>();
ArrayList<Item> kal = new ArrayList<Item>();
public Fileslist(String path) throws NetworkIOException, DbxException, IOException
{
addFolders(path);
int count=0;
JScrollPane panel= new JScrollPane();
JScrollPane mainpanel= new JScrollPane();
DefaultListModel<String> model= new DefaultListModel<String>();
JPanel jaypanel = new JPanel();
for(Container c : folderbuttons)
{
jaypanel.add(c);
}
for(DbxEntry c: filesandfolders)
{
if(c.isFile())
{
if(model.contains(c.name+" "+" File"+" "+c.asFile().lastModified))
{
model.addElement(c.name+" "+" File"+" "+c.asFile().lastModified);
}
}
}
JList<String> filesfolders= new JList<String>(model);
filesfolders.setSelectionMode (ListSelectionModel.SINGLE_SELECTION);
Container c = new Container();
c.add(filesfolders);
panel.add(c);
panel.setSize(200,200);
JTextField text = new JTextField("",2);
text.addKeyListener(new KeyAdapter()
{
public void keyTyped(KeyEvent e)
{
if (e.getKeyChar() == KeyEvent.VK_ENTER)
{
try {
ArrayList<Item> black=getFilesStartingWith(path, text.getText());
DbxClientV1 client = new DbxClientV1(config, ACCESS_TOKEN);
client.createFolder(path+"/"+text.getText());
System.out.println("Entered: "+ text.getText());
for(int i=0; i<black.size();i++)
{
client.move("/"+black.get(i).mainpath, "/"+black.get(i).mainpath+"/"+text.getText()+"/"+black.get(i).name);
}
System.out.println("Entered: "+ text.getText());
}
catch (DbxException e1)
{
e1.printStackTrace();
}
System.out.println("Entered:"+ text.getText());
}
}
});
jaypanel.setSize(400, 400);
mainpanel.add(jaypanel);
mainpanel.setSize(400,400);
mainpanel.setLayout(new ScrollPaneLayout());
getContentPane().add(mainpanel);
getContentPane().add(panel);
getContentPane().add(text);
if(filesandfolders.size()==0)
{
System.out.println("No files");
}
setSize(600, 600);
repaint();
setLayout(new GridLayout(3,3));
setVisible(true);
}
public void addFolders(String path) throws NetworkIOException, DbxException, IOException
{
ArrayList<String> folders= new ArrayList<String>();
folders.add("/");
int count=0;
DbxClientV1 client = new DbxClientV1(config, ACCESS_TOKEN);
List<Metadata> newmeta= new ArrayList<Metadata>(2);
folders=getAllFolders2(newmeta, client);
WithChildren result = client.getMetadataWithChildren(path, true);
filesandfolders = result.children;
for(String kal:folders)
{
JButton addtoMain= new JButton(kal);
addtoMain.setSize(150,150);
addtoMain.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
//Execute when button is pressed
try {
Fileslist filesframe=new Fileslist(kal);
} catch (NetworkIOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (DbxException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
});
Container contain= new Container();
contain.setSize(150, 150);
contain.setLayout(new FlowLayout());
contain.add(addtoMain);
folderbuttons.add(contain);
folderbuttons2.add(addtoMain);
}
}
public ArrayList<Item> getFilesStartingWith(String path, String key) throws DbxException
{
ArrayList<Item> files = new ArrayList();
DbxClientV1 client = new DbxClientV1(config, ACCESS_TOKEN);
WithChildren result = client.getMetadataWithChildren(path, true);
List<DbxEntry> cursor3 = result.children;
for (DbxEntry entry : cursor3)
{
if(entry.isFile())
{
Item newItem = new Item(entry.path, path, entry.name);
kal.add(newItem);
}
}
for(int i=0; i<kal.size();i++)
{
if(kal.get(i).name.startsWith(key))
{
System.out.println(path+" has under:*** "+kal.get(i).path+" also called "+kal.get(i).name);
files.add(kal.get(i));
}
}
return files;
}
}
This gives the following result: http://i558.photobucket.com/albums/ss30/magpiejay/Balksz_zpsuxdv6fvl.jpg~original
Where the end of the scrolling button is lost, and TextArea is unnecessarily large. So, what's going on?
Edit: Okay, I seemingly solved the problem. It was because I was adding elements directly to JScrollPane, instead of using .setViewportView().
((There was also an unrelated issue with the if clause, it was originally supposed to be the opposite of the current one)).