Page 1 of 2 12 LastLast
Results 1 to 20 of 29
  1. #1
    Radu is offline Member
    Join Date
    Dec 2009
    Posts
    29
    Rep Power
    0

    Question jList like a FileListBox

    Hello!
    Can someone help me with the code to make a jList that is showing the files from a folder?
    From example to show *.* from D:\Test in a jList or something similar to a ListBox or FileListBox from Visual Basic.

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Your best bet is to go through the Sun tutorials on JList and on File handling, then try to play with some code, and come on back posting your code if you run into a problem and let's see what we can do with it.

    Helpful links:
    Sun Java Tutorials
    Sun Swing Tutorials
    JList Tutorial
    File Tutorial
    SSCCE

    Much luck

  3. #3
    Radu is offline Member
    Join Date
    Dec 2009
    Posts
    29
    Rep Power
    0

    Default

    I made this to show all files from a specified folder but I want to see them in a jList or something like that as I sad and NOT in a tree like in tutorials.

  4. #4
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,457
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by Radu View Post
    Hello!
    Can someone help me with the code to make a jList that is showing the files from a folder?
    From example to show *.* from D:\Test in a jList or something similar to a ListBox or FileListBox from Visual Basic.
    I bet you haven't even skimmed through the API documentation because this is just a no-brainer: new JList(new File("D:/Test").list()); of course you can add more bells and whistles to this tiny code snippet. Always first study the tutorials (as has been suggested by Fubarable) and study the API documentation. If you don't you keep on asking for the obvious.

    kind regards,

    Jos

  5. #5
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by Radu View Post
    I made this to show all files from a specified folder but I want to see them in a jList or something like that as I sad and NOT in a tree like in tutorials.
    And that's why I included the JList tutorial! You are allowed to look at more than one tutorial and combine the information in your brain. :)

  6. #6
    Radu is offline Member
    Join Date
    Dec 2009
    Posts
    29
    Rep Power
    0

    Arrow

    1) What line should I delete to show me only the files -- without details (bytes) and without folders?

    2) Were should I modify the directory that is listed (I need to view files from D:\Test)?

    Java Code:
    package plm;
    import java.awt.*;
    import javax.swing.*;
    import java.io.*;
    
    public class PolymorphicJList extends JList {
    
       private static final long serialVersionUID = 1L;
    
       static Color listForeground, listBackground,
            listSelectionForeground, listSelectionBackground;
        static {
            UIDefaults uid = UIManager.getLookAndFeel().getDefaults();
            listForeground =  uid.getColor ("List.foreground");
            listBackground =  uid.getColor ("List.background");
            listSelectionForeground =  uid.getColor ("List.selectionForeground");
            listSelectionBackground =  uid.getColor ("List.selectionBackground");
        }
    
        ImageIcon fileIcon, textFileIcon, directoryIcon,
            imageFileIcon, pngFileIcon, gifFileIcon,
            jpegFileIcon;
        JComponent fileCellPrototype, textCellPrototype,
            imageCellPrototype, directoryCellPrototype;
        JLabel fileNameLabel, textNameLabel,
            directoryNameLabel, imageNameLabel,
            fileSizeLabel,
            textSizeLabel, textWordCountLabel,
            directoryCountLabel,
            imageSizeLabel, imageIconLabel;
    
        public PolymorphicJList  (File dir) {
            super();
            buildPrototypeCells();
            setCellRenderer (new PolyRenderer());
            setModel (new DefaultListModel());
            if (! dir.isDirectory())
                dir = new File (dir.getParent());
            buildModelFromDir (dir);
        }
    
        public static void main (String[] args) {
            File dir = new File (".");
            if (args.length > 0)
                dir = new File (args[0]);
            JList list = new PolymorphicJList (dir);
            JScrollPane pain =
                new JScrollPane (list,
                                 ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
                                 ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
            JFrame frame = new JFrame ("PolymorphicJList");
            frame.getContentPane().add (pain);
            frame.pack();
            frame.setVisible(true);
        }
    
        protected void buildModelFromDir (File dir) {
            File[] files = dir.listFiles();
            DefaultListModel mod = (DefaultListModel) getModel();
            for (int i=0; i<files.length; i++) {
                if (isTextFile (files[i]))
                    mod.addElement (new TextFileItem (files[i]));
                else if (isImageFile (files [i]))
                    mod.addElement (new ImageFileItem (files[i]));
                else if (files[i].isDirectory())
                    mod.addElement (new DirectoryItem (files[i]));
                else
                    mod.addElement (new FileItem (files[i]));
            }
        }
    
        protected boolean isImageFile(File f) {
            if (f.isDirectory())
                return false;
            String name = f.getName();
            return name.endsWith (".gif") || name.endsWith (".GIF") ||
                name.endsWith (".jpg") || name.endsWith (".JPG") ||
                name.endsWith (".jpeg") || name.endsWith (".JPEG") ||
                name.endsWith (".bmp") || name.endsWith (".BMP") ||
                name.endsWith (".png") || name.endsWith (".PNG");
        }
    
        protected boolean isTextFile(File f) {
            if (f.isDirectory())
                return false;
            String name = f.getName();
            return name.endsWith (".txt") || name.endsWith (".html") ||
                name.endsWith (".xml") || name.endsWith (".xhtml") ||
                name.endsWith (".java") || name.endsWith (".c") ||
                name.endsWith (".cpp") || name.endsWith (".c++") ||
                name.endsWith (".m") || name.endsWith (".h");
        }
    
        protected void buildIcons() {
            String SEP = System.getProperty ("file.separator");
            fileIcon = new ImageIcon ("images" + SEP + "generic.gif");
            textFileIcon = new ImageIcon ("images" + SEP + "text.gif");
            directoryIcon = new ImageIcon ("images" + SEP + "folder.gif");
            imageFileIcon = new ImageIcon ("images" + SEP + "image.gif");
            pngFileIcon = new ImageIcon ("images" + SEP + "png.gif");
            gifFileIcon = new ImageIcon ("images" + SEP + "gif.gif");
            jpegFileIcon = new ImageIcon ("images" + SEP + "jpeg.gif");
        }
    
        protected void buildPrototypeCells() {
            buildIcons();
            fileCellPrototype = new JPanel();
            fileCellPrototype.setLayout (new GridBagLayout());
            addWithGridBag (new JLabel(fileIcon), fileCellPrototype,
                            0, 0, 1, 2,
                            GridBagConstraints.WEST, GridBagConstraints.BOTH, 0, 0);
            fileNameLabel = new JLabel();
            Font defaultLabelFont = fileNameLabel.getFont();
            Font nameFont = defaultLabelFont.deriveFont (Font.BOLD,
                                                         defaultLabelFont.getSize()+2);
            fileNameLabel.setFont (nameFont);
            addWithGridBag (fileNameLabel, fileCellPrototype,
                            1, 0, 1, 1,
                            GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL, 1, 0);
            fileSizeLabel = new JLabel();
            addWithGridBag (fileSizeLabel, fileCellPrototype,
                            1, 1, 1, 1,
                            GridBagConstraints.SOUTH, GridBagConstraints.HORIZONTAL, 1, 0);
            opacify (fileCellPrototype);
            // text file
            textCellPrototype = new JPanel();
            textCellPrototype.setLayout (new GridBagLayout());
            addWithGridBag (new JLabel(textFileIcon), textCellPrototype,
                            0, 0, 1, 2,
                            GridBagConstraints.WEST, GridBagConstraints.BOTH, 0, 0);
            textNameLabel = new JLabel();
            textNameLabel.setFont (nameFont);
            addWithGridBag (textNameLabel, textCellPrototype,
                            1, 0, 2, 1,
                            GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL, 1, 0);
            textSizeLabel = new JLabel();
            textWordCountLabel = new JLabel();
            addWithGridBag (textSizeLabel, textCellPrototype,
                            1, 1, 1, 1,
                            GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL, 0, 0);
            addWithGridBag (textWordCountLabel, textCellPrototype,
                            2, 1, 1, 1,
                            GridBagConstraints.SOUTH, GridBagConstraints.HORIZONTAL, 1, 0);
    
            opacify (textCellPrototype);
            // directory
            directoryCellPrototype = new JPanel();
            directoryCellPrototype.setLayout (new GridBagLayout());
            addWithGridBag (new JLabel(directoryIcon), directoryCellPrototype,
                            0, 0, 1, 2,
                            GridBagConstraints.WEST, GridBagConstraints.BOTH, 0, 0);
            directoryNameLabel = new JLabel();
            directoryNameLabel.setFont (nameFont);
            addWithGridBag (directoryNameLabel, directoryCellPrototype,
                            1, 0, 1, 1,
                            GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL, 1, 0);
            directoryCountLabel = new JLabel();
            addWithGridBag (directoryCountLabel, directoryCellPrototype,
                            1, 1, 1, 1,
                            GridBagConstraints.SOUTH, GridBagConstraints.HORIZONTAL, 1, 0);
            opacify (directoryCellPrototype);
            // image
            imageCellPrototype = new JPanel();
            imageCellPrototype.setLayout (new GridBagLayout());
            addWithGridBag (new JLabel(imageFileIcon), imageCellPrototype,
                            0, 0, 1, 2,
                            GridBagConstraints.WEST, GridBagConstraints.BOTH, 0, 0);
            imageNameLabel = new JLabel();
            imageNameLabel.setFont (nameFont);
            addWithGridBag (imageNameLabel, imageCellPrototype,
                            1, 0, 1, 1,
                            GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL, 1, 0);
            imageSizeLabel = new JLabel();
            addWithGridBag (imageSizeLabel, imageCellPrototype,
                            1, 1, 1, 1,
                            GridBagConstraints.SOUTH, GridBagConstraints.HORIZONTAL, 1, 0);
            imageIconLabel = new JLabel();
            addWithGridBag (imageIconLabel, imageCellPrototype,
                            2, 0, 1, 2,
                            GridBagConstraints.EAST, GridBagConstraints.VERTICAL, 0, 0);
            opacify (imageCellPrototype);
        }
    
        private void addWithGridBag (Component comp, Container cont,
                                     int x, int y,
                                     int width, int height,
                                     int anchor, int fill,
                                     int weightx, int weighty) {
            GridBagConstraints gbc = new GridBagConstraints();
            gbc.gridx = x;
            gbc.gridy = y;
            gbc.gridwidth = width;
            gbc.gridheight = height;
            gbc.anchor = anchor;
            gbc.fill = fill;
            gbc.weightx = weightx;
            gbc.weighty = weighty;
            cont.add (comp, gbc);
        }
    
        private void opacify (Container prototype) {
            Component[] comps = prototype.getComponents();
            for (int i=0; i<comps.length; i++) {
                if (comps[i] instanceof JComponent)
                    ((JComponent)comps[i]).setOpaque(true);
            }
        }
    
    
        class FileItem extends Object {
            File file;
            public FileItem (File f) {
                file = f;
            }
        }
    
        class ImageFileItem extends FileItem {
            ImageIcon icon;
            public ImageFileItem (File f) {
                super(f);
                initIcon();
            }
            void initIcon() {
                icon = new ImageIcon (file.getPath());
                // scale to 32 pix in largest dimension
                Image img = icon.getImage();
                float factor = 1.0f;
                if (img.getWidth(null) > img.getHeight(null))
                    factor = Math.min (32f / img.getWidth(null), 1.0f);
                else
                    factor = Math.min (32f / img.getHeight(null), 1.0f);
                Image scaledImage =
                    img.getScaledInstance ((int) (img.getWidth(null) * factor),
                                           (int) (img.getHeight(null) * factor),
                                           Image.SCALE_FAST);
                icon.setImage(scaledImage);
            }
        }
    
    
        class DirectoryItem extends FileItem {
            int childCount;
            public DirectoryItem (File f) {
                super(f);
                initChildCount();
            }
            public int getChildCount() { return childCount; }
            void initChildCount () {
                if (! file.isDirectory())
                    childCount = -1;
                else
                    childCount = file.listFiles().length;
                System.out.println (file.getPath() + ": " + childCount + " items");
            }
        }
    
    
        class TextFileItem extends FileItem {
            int wordCount = -1;
            public TextFileItem (File f) {
                super(f);
                initWordCount();
            }
            public int getWordCount() { return wordCount; }
            protected void initWordCount() {
                try {
                    StreamTokenizer izer =
                        new StreamTokenizer (new BufferedReader (new FileReader(file)));
                    while (izer.nextToken() != StreamTokenizer.TT_EOF)
                        wordCount++;
                } catch (Exception e) {
                    e.printStackTrace();
                    wordCount = -1;
                }
                System.out.println (file.getPath() + ": " + wordCount + " words");
            }
        }
    
        class PolyRenderer extends Object
            implements ListCellRenderer {
    
            public Component getListCellRendererComponent(JList list,
                                                          Object value,
                                                          int index,
                                                          boolean isSelected,
                                                          boolean cellHasFocus) {
                if (value instanceof DirectoryItem) {
                    DirectoryItem item = (DirectoryItem) value;
                    directoryNameLabel.setText (item.file.getName());
                    directoryCountLabel.setText (item.getChildCount() + " items");
                    setColorsForSelectionState (directoryCellPrototype, isSelected);
                    return directoryCellPrototype;
                } else if (value instanceof TextFileItem) {
                    TextFileItem item = (TextFileItem) value;
                    // populate values
                    textNameLabel.setText (item.file.getName());
                    textSizeLabel.setText (item.file.length() + " bytes  ");
                    textWordCountLabel.setText (item.getWordCount() + " words");
                    setColorsForSelectionState (textCellPrototype, isSelected);
                    return textCellPrototype;
                } else if (value instanceof ImageFileItem) {
                    ImageFileItem item = (ImageFileItem) value;
                    // pouplate values
                    imageNameLabel.setText (item.file.getName());
                    imageSizeLabel.setText (item.file.length() + " bytes");
                    imageIconLabel.setIcon (item.icon);
                    setColorsForSelectionState (imageCellPrototype, isSelected);
                    return imageCellPrototype;
                } else {
                    FileItem item = (FileItem) value;
                    // pouplate values
                    fileNameLabel.setText (item.file.getName());
                    fileSizeLabel.setText (item.file.length() + " bytes");
                    setColorsForSelectionState (fileCellPrototype, isSelected);
                    return fileCellPrototype;
                }
            }
            private void setColorsForSelectionState (Container prototype,
                                                     boolean isSelected) {
                Component[] comps = prototype.getComponents();
                for (int i=0; i<comps.length; i++) {
                    if (isSelected) {
                        comps[i].setForeground (listSelectionForeground);
                        comps[i].setBackground (listSelectionBackground);
                    } else {
                        comps[i].setForeground (listForeground);
                        comps[i].setBackground (listBackground);
                    }
                }
            }
        }
    }

  7. #7
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,457
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by Radu View Post
    1) What line should I delete to show me only the files -- without details (bytes) and without folders?

    2) Were should I modify the directory that is listed (I need to view files from D:\Test)?
    I bet that is not your code: you don't understand it and you're behaving like a surgeon: cut away bits and pieces and hope for the best. This is not the way you develop a program. Have a look at that code snippet I supplied; most likely it doesn't do all you want; you have to read the API documentation (I bet you didn't do that either yet) and construct the code you want. I gave you a starting point.

    kind regards,

    Jos

  8. #8
    Radu is offline Member
    Join Date
    Dec 2009
    Posts
    29
    Rep Power
    0

    Default

    of course is not my code.

    where should i put that new JList(new File("D:/Test").list()); code in the program?

  9. #9
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,457
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by Radu View Post
    of course is not my code.

    where should i put that new JList(new File("D:/Test").list()); code in the program?
    You don't need any other code: that snippet gives you a JList properly initialized with all entries from the D:/Test directory. Put that list whereever you want. It is next to impossible to stick that code snippet in a large piece of code that doesn't anticipate for it. Please read the API documentation and stop guessing and begging to be spoonfed.

    kind regards,

    Jos

  10. #10
    Radu is offline Member
    Join Date
    Dec 2009
    Posts
    29
    Rep Power
    0

    Angry

    OK! I managed to do that.
    Now I don't know another thing.
    How can I see in 2 jLists all files from 2 different folders by clicking one item in another jList.

    Basically I have 3 jList:
    jList1 with items: item1, item2 and item3
    and jList2 and jList3 in wich will be displayed 2 different folders.

    If I click item1 in jList1 in jList2 will be displayed *.* from d:\trs\item1 and in jList3 will be displayed *.* from d:\rec\item1


    If I click item2 in jList1 in jList2 will be displayed *.* from d:\trs\item2 and in jList3 will be displayed *.* from d:\rec\item2



    P.S. If you don't uderstand I can attach my code to this post to see my project.
    Attached Thumbnails Attached Thumbnails jList like a FileListBox-programul2.jpg  

  11. #11
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    The JList tutorials that I linked to above will help you react to the user's selecting an item in your first list. I would recommend that your JLists each use a DefaultListModel (<-- to API link) as their models and then based on the first list's selection use this information to fill the models of the other two JLists by calling the models' addElement method.

    Why not give it a try, and if you hit a snag, come back with your code. We'd best be able to analyze your code if it is in the form of an SSCCE (also linked above).

    Best of luck.

  12. #12
    Radu is offline Member
    Join Date
    Dec 2009
    Posts
    29
    Rep Power
    0

    Thumbs down

    This program is out of my understanding. I can't make it work.


    Java Code:
    
    
    package RxFer;
    
    import javax.swing.DefaultListModel;
    import java.util.List;
    import java.io.File;
    import java.util.ArrayList;
    
    public class Main extends javax.swing.JFrame {
    
    
    
       private DefaultListModel listModel1, listModel2;
    
       private List<File> current_file_list;
    
        public Main() {
            InitializareComponente();
        }
    
        
        
        
            private void Filme (java.awt.event.ActionEvent evt) {   
            String path_to_directory = jTextField.getText();
            if(current_file_list != null)
                current_file_list.clear();
            render(path_to_directory);
        }  
        
        
        
        
        
        
        
        
    
    
        private void InitializareComponente() {
    
            GrupuriPanel = new javax.swing.JPanel();
            GrupuriScrollPane = new javax.swing.JScrollPane();
            Grupuri = new javax.swing.JList();
            DeTransmisPanel = new javax.swing.JPanel();
            DeTransmisScrollPane = new javax.swing.JScrollPane();
            DeTransmis = new javax.swing.JList();
            ReceptionatePanel = new javax.swing.JPanel();
            ReceptionateScrollPane = new javax.swing.JScrollPane();
            Receptionate = new javax.swing.JList();
            ProgressBar = new javax.swing.JProgressBar();
            Meniu = new javax.swing.JMenuBar();
            Upload = new javax.swing.JMenu();
            UploadS = new javax.swing.JMenuItem();
            UploadSeparator = new javax.swing.JSeparator();
            UploadP = new javax.swing.JMenuItem();
            Download = new javax.swing.JMenu();
            DownloadS = new javax.swing.JMenuItem();
            DownloadSeparator = new javax.swing.JSeparator();
            DownloadP = new javax.swing.JMenuItem();
            Bridge = new javax.swing.JMenu();
            TransferBridge = new javax.swing.JMenuItem();
            Iesire = new javax.swing.JMenu();
            IesireRxFer = new javax.swing.JMenuItem();
    
            setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
            setTitle("...:: RxFer ::...");
            setResizable(false);
            this.listModel1 = new DefaultListModel();
            this.listModel2 = new DefaultListModel();
            this.current_file_list = new ArrayList<File>();
            GrupuriPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(" Grupuri: "));
            this.DeTransmis.setModel(listModel1);
            this.Receptionate.setModel(listModel2);
    
    
            Grupuri.setModel(new javax.swing.AbstractListModel() {
                String[] strings = { "Filme", "Muzica", "Imagini" };
                public int getSize() { return strings.length; }
                public Object getElementAt(int i) { return strings[i]; }
            });
            Grupuri.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
            GrupuriScrollPane.setViewportView(Grupuri);
    
            javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(GrupuriPanel);
            GrupuriPanel.setLayout(jPanel1Layout);
            jPanel1Layout.setHorizontalGroup(
                jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(GrupuriScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 188, Short.MAX_VALUE)
            );
            jPanel1Layout.setVerticalGroup(
                jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(GrupuriScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 378, Short.MAX_VALUE)
            );
    
            DeTransmisPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(" Fisiere de transmis: "));
    
            DeTransmisScrollPane.setViewportView(DeTransmis);
    
            javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(DeTransmisPanel);
            DeTransmisPanel.setLayout(jPanel2Layout);
            jPanel2Layout.setHorizontalGroup(
                jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(DeTransmisScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 188, Short.MAX_VALUE)
            );
            jPanel2Layout.setVerticalGroup(
                jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(DeTransmisScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 378, Short.MAX_VALUE)
            );
    
            ReceptionatePanel.setBorder(javax.swing.BorderFactory.createTitledBorder(" Fisiere receptionate: "));
    
            ReceptionateScrollPane.setViewportView(Receptionate);
    
            javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(ReceptionatePanel);
            ReceptionatePanel.setLayout(jPanel3Layout);
            jPanel3Layout.setHorizontalGroup(
                jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(ReceptionateScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 188, Short.MAX_VALUE)
            );
            jPanel3Layout.setVerticalGroup(
                jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(ReceptionateScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 378, Short.MAX_VALUE)
            );
    
            ProgressBar.setPreferredSize(new java.awt.Dimension(146, 15));
    
            Upload.setText("Upload");
    
            UploadS.setText("Upload S");
            Upload.add(UploadS);
            Upload.add(UploadSeparator);
    
            UploadP.setText("Upload P");
            Upload.add(UploadP);
    
            Meniu.add(Upload);
    
            Download.setText("Download");
    
            DownloadS.setText("Download S");
            Download.add(DownloadS);
            Download.add(DownloadSeparator);
    
            DownloadP.setText("Download P");
            Download.add(DownloadP);
    
            Meniu.add(Download);
    
            Bridge.setText("Bridge");
    
            TransferBridge.setText("Transfer Bridge");
            Bridge.add(TransferBridge);
    
            Meniu.add(Bridge);
            
            Iesire.setText("Quit");
    
            IesireRxFer.setText("Quit RxFer");
            IesireRxFer.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    System.exit(0);
                }
            });
            Iesire.add(IesireRxFer);
    
            Meniu.add(Iesire);
    
            setJMenuBar(Meniu);
    
            javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
            getContentPane().setLayout(layout);
            layout.setHorizontalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                    .addContainerGap()
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                        .addComponent(ProgressBar, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 200, Short.MAX_VALUE)
                        .addComponent(GrupuriPanel, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(DeTransmisPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(ReceptionatePanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addContainerGap())
            );
            layout.setVerticalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addContainerGap()
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                        .addComponent(ReceptionatePanel, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(DeTransmisPanel, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(GrupuriPanel, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                    .addComponent(ProgressBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addContainerGap())
            );
    
             java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
            setBounds((screenSize.width-648)/2, (screenSize.height-512)/2, 648, 512);
    
    
        }
                public void render(String path_to_directory)
        {
            File dir = new File(path_to_directory);
    
            if(!dir.exists())
            {
                listModel1.add(0, "Director inexistent!");
            }
            else
            {
                File fisiere[] = dir.listFiles();
                if(fisiere.length == 0)
                {
                    listModel1.add(0, "Directorul este gol!");
                }
                else
                {
                    for(int i = 0; i < fisiere.length; i++)
                    {
                        listModel1.add(i, fisiere[i].getName());
                        current_file_list.add(i, fisiere[i]);
                    }
                }
            }
    
    
    
    
    
    
            pack();
        }
    
    
        public static void main(String args[]) {
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    new Main().setVisible(true);
                }
            });
        }
    
        private javax.swing.JList Grupuri;
        private javax.swing.JList DeTransmis;
        private javax.swing.JList Receptionate;
        private javax.swing.JMenu Upload;
        private javax.swing.JMenu Download;
        private javax.swing.JMenu Bridge;
        private javax.swing.JMenu Iesire;
        private javax.swing.JMenuBar Meniu;
        private javax.swing.JMenuItem UploadS;
        private javax.swing.JMenuItem UploadP;
        private javax.swing.JMenuItem DownloadS;
        private javax.swing.JMenuItem DownloadP;
        private javax.swing.JMenuItem TransferBridge;
        private javax.swing.JMenuItem IesireRxFer;
        private javax.swing.JPanel GrupuriPanel;
        private javax.swing.JPanel DeTransmisPanel;
        private javax.swing.JPanel ReceptionatePanel;
        private javax.swing.JProgressBar ProgressBar;
        private javax.swing.JScrollPane GrupuriScrollPane;
        private javax.swing.JScrollPane DeTransmisScrollPane;
        private javax.swing.JScrollPane ReceptionateScrollPane;
        private javax.swing.JSeparator DownloadSeparator;
        private javax.swing.JSeparator UploadSeparator;
    
    }

  13. #13
    Radu is offline Member
    Join Date
    Dec 2009
    Posts
    29
    Rep Power
    0

    Default

    Hmmm... Nobody?

  14. #14
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by Radu View Post
    Hmmm... Nobody?
    Yes, you.

    You've got borrowed code that you can't understand, and I doubt anyone is going to have the time to go step-by-step through this code that's not theirs. The best solution to this problem is to either write code you do understand or do enough reading so you understand the borrowed code. Much luck.

  15. #15
    Radu is offline Member
    Join Date
    Dec 2009
    Posts
    29
    Rep Power
    0

    Default

    Some of you java programmers suck (Fubarable is one of them). I don't know what is making you so selfish.


    I REALLY DON'T CARE IF YOU WILL BAN MY ACCOUNT!

  16. #16
    coltragon is offline Senior Member
    Join Date
    Dec 2009
    Posts
    104
    Rep Power
    0

    Default

    wow, 2 days ago, you didn't know anything about the file functions.
    and now you can write that program, you're a fast learner ;)

    of course, if you STEAL a code from someone else, you won't understand it

  17. #17
    Radu is offline Member
    Join Date
    Dec 2009
    Posts
    29
    Rep Power
    0

    Default

    I don't want to learn any java. I know vb.net and c++. I want to create this program to help me in my work. I alleady done it in vb.net but i can't run it at my work beacuse i don't have any vb or c++ there and I don't work as a programmer

  18. #18
    coltragon is offline Senior Member
    Join Date
    Dec 2009
    Posts
    104
    Rep Power
    0

    Default

    you can't compile it too an exe?

  19. #19
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,457
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by Radu View Post
    I don't want to learn any java. I know vb .net and c++. I want to create this program to help me in my work. I alleady done it in vb.net but i can't run it at my work beacuse i don't have any vb or c++ there.
    So install C++ and/or VB 'at your work'; the Microsoft Express editions are free downloadable editions. Goodbye.

    Jos

  20. #20
    coltragon is offline Senior Member
    Join Date
    Dec 2009
    Posts
    104
    Rep Power
    0

    Default

    Quote Originally Posted by JosAH View Post
    So install C++ and/or VB 'at your work'; the Microsoft Express editions are free downloadable editions. Goodbye.

    Jos
    laughing hard at that part :P

Page 1 of 2 12 LastLast

Similar Threads

  1. How to use a JList?
    By glhansen in forum New To Java
    Replies: 3
    Last Post: 03-24-2009, 10:27 AM
  2. JList
    By pinks_70986 in forum New To Java
    Replies: 1
    Last Post: 02-12-2009, 08:36 AM
  3. About JList
    By hungleon88 in forum Advanced Java
    Replies: 5
    Last Post: 08-30-2008, 09:24 PM
  4. Help with JList
    By Albert in forum NetBeans
    Replies: 1
    Last Post: 07-13-2007, 03:42 PM
  5. add a jlist column
    By Alan in forum JCreator
    Replies: 1
    Last Post: 05-28-2007, 04:51 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •