Click to See Complete Forum and Search --> : jList help
MadSkillz
December 4th, 2009, 04:20 PM
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!
dlorde
December 4th, 2009, 05:35 PM
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
MadSkillz
December 5th, 2009, 12:20 AM
if i click the 1st Jlist ITEM1 in the 2nd list will be displayed *.* of D:\REC\ITEM1 and in the 3rd Jlist will be despayed *.* of D:\TRS\ITEM1
if i click the 1st Jlist ITEM2 in the 2nd list will be displayed *.* of D:\REC\ITEM2 and in the 3rd Jlist will be despayed *.* of D:\TRS\ITEM2
if i click the 1st Jlist ITEM3 in the 2nd list will be displayed *.* of D:\REC\ITEM3 and in the 3rd Jlist will be despayed *.* of D:\TRS\ITEM3
and so on...
keang
December 5th, 2009, 04:45 AM
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.
MadSkillz
December 6th, 2009, 01:21 AM
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.
keang
December 7th, 2009, 08:47 AM
Hmmm... Can you help me with the code...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.
dlorde
December 8th, 2009, 07:33 AM
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
MadSkillz
December 8th, 2009, 03:21 PM
public class RxFer_v3Frame extends javax.swing.JFrame {
public RxFer_v3Frame() {
initComponents();
}
@SuppressWarnings("unchecked")
private void initComponents() {
jPanel1 = new javax.swing.JPanel();
jScrollPane1 = new javax.swing.JScrollPane();
jList1 = new javax.swing.JList();
jPanel2 = new javax.swing.JPanel();
jScrollPane2 = new javax.swing.JScrollPane();
jList2 = new javax.swing.JList();
jPanel3 = new javax.swing.JPanel();
jScrollPane3 = new javax.swing.JScrollPane();
jList3 = new javax.swing.JList();
jProgressBar1 = new javax.swing.JProgressBar();
jMenuBar1 = new javax.swing.JMenuBar();
jMenu1 = new javax.swing.JMenu();
jMenuItem1 = new javax.swing.JMenuItem();
jSeparator2 = new javax.swing.JSeparator();
jMenuItem2 = new javax.swing.JMenuItem();
jMenu2 = new javax.swing.JMenu();
jMenuItem3 = new javax.swing.JMenuItem();
jSeparator1 = new javax.swing.JSeparator();
jMenuItem4 = new javax.swing.JMenuItem();
jMenu3 = new javax.swing.JMenu();
jMenuItem5 = new javax.swing.JMenuItem();
if i click the 1st Jlist Esa in the 2nd jlist will be displayed *.* of D:\REC\Esa and in the 3rd Jlist will be despayed *.* of D:\TRS\Esa
if i click the 1st Jlist Escl in the 2nd jlist will be displayed *.* of D:\REC\Escl and in the 3rd Jlist will be despayed *.* of D:\TRS\Escl
if i click the 1st Jlist Media in the 2nd jlist will be displayed *.* of D:\REC\Media and in the 3rd Jlist will be despayed *.* of D:\TRS\Media
and so on...
dlorde
December 8th, 2009, 06:42 PM
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.
MadSkillz
December 9th, 2009, 01:34 AM
I posted an image too.
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
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);
MadSkillz
December 9th, 2009, 05:03 AM
I bought The Definitive Guide to NetBeans Platform 6.5 but there is nothing there about showing files in a jList.
keang
December 9th, 2009, 05:36 AM
try reading this (http://java.sun.com/docs/books/tutorial/uiswing/events/index.html)
MadSkillz
December 12th, 2009, 11:20 AM
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.
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]);
}
}
}
dlorde
December 13th, 2009, 06:06 AM
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 (http://java.sun.com/docs/books/tutorial/uiswing/components/list.html) ?
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
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.