Hello!
I have 3 jLists (jList1, jList2, jList3).
Is there any way that I can click on one item in the 1st jList and view the content (the files in the folder) of 2 different folders in the other 2 jLists at the same time? Help me with the code pls! Thank you!
I think the answer is probably 'yes', but you'll have to explain more clearly what you want. How are the 2 folders displayed in the 2nd & 3rd JLists related to the item clicked in the 1st JList?
The hardest part of the software task is arriving at a complete and consistent specification, and much of the essence of building a program is in fact the debugging of the specification...
F. Brooks
Please use [CODE]...your code here...[/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present.
Create a File object for the directory you want to display the contents of and call it's list() method to obtain a list of the files in the directory. Use this array of file names to populate the JList.
If you want to restrict the type of files to display there is a list(..) method that takes a FilenameFilter object. You can use this to filter the names to be included in the list for example to only include files with a .txt extension or files beginning with 'S' etc.
Create a File object for the directory you want to display the contents of and call it's list() method to obtain a list of the files in the directory. Use this array of file names to populate the JList.
If you want to restrict the type of files to display there is a list(..) method that takes a FilenameFilter object. You can use this to filter the names to be included in the list for example to only include files with a .txt extension or files beginning with 'S' etc.
Hmmm... Can you help me with the code, if you don't mind. I'm a beginner and I'm learning from examples.
Err No. The best way to learn is to try to do it yourself.
I've explained what you should be trying to do, now it's your turn to put some effort in. If you get stuck post your code and we will help but it's unlikely anyone here is going to write it for you.
Hmmm... Can you help me with the code, if you don't mind. I'm a beginner and I'm learning from examples.
I'll help you with the code - just post the code you need help with and explain exactly what part you are having difficulty with.
Learning results from what the student does and thinks, and only from what the student does and thinks. The teacher can advance learning only by influencing the student to learn...
H. Simon
Please use [CODE]...your code here...[/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present.
No, I didn't mean post empty method bodies for the bit you need help with, I meant post your attempt to solve the problem (i.e. fill in the missing code) and explain exactly where you are getting stuck with it.
If you're not going to bother to try to solve your problem, I certainly won't.
If I had eight hours to chop down a tree, I would spend 6 hours sharpening an axe...
Anon.
Please use [CODE]...your code here...[/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present.
I need an event or something that when I'm clicking on a certain item ("Esa", "Escl", "Media") from this jlist to open in the other 2 jlists 2 different directories
Code:
jList1 = new javax.swing.JList();
jList1.setModel(new javax.swing.AbstractListModel() {
String[] strings = { "Esa", "Escl", "Media" };
public int getSize() { return strings.length; }
public Object getElementAt(int i) { return strings[i]; }
});
jScrollPane1.setViewportView(jList1);
i made this program to list all files and folders from a specified location. but how to make them be displayed in a jList? Help me with the code pls. I already have headache.
Code:
import java.io.File;
import java.util.Scanner;
public class DirectoryList {
public static void main(String[] args) {
String directoryName;
File directory;
String[] files;
Scanner scanner;
scanner = new Scanner(System.in);
System.out.print("Enter a directory name: ");
directoryName = scanner.nextLine().trim();
directory = new File(directoryName);
if (directory.isDirectory() == false) {
if (directory.exists() == false)
System.out.println("There is no such directory!");
else
System.out.println("That file is not a directory.");
}
else {
files = directory.list();
System.out.println("Files in directory \"" + directory + "\":");
for (int i = 0; i < files.length; i++)
System.out.println(" " + files[i]);
}
}
}
This really isn't rocket science... have you read the JList API doc with its examples? Have you read the Java Tutorial on How To Use Lists ?
If so, please explain exactly which part of displaying a list of files in a JList you are stuck on.
Remember, you can add a collection or array of elements to a JList when you construct it, but if you want to add individual elements, you need to create the ListModel (use DefaultListModel) yourself and add the elements to that.
Good teaching is more a giving of the right questions than a giving of the right answers...
J. Albers
Please use [CODE]...your code here...[/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present.
* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.