© 2014 Firstsoft Technologies (P) Limited. login
Hi 'Guest'
Home SiteMap Contact Us Disclaimer
Quick Links
Easy Studies

Java Swing List for display files names


This program gets the details of a file from the specifed folder. It takes folder name as input and get the name of files and display it using the JList. This program creates the File object for the given directory. From this it gets the File list using the list() method.File lists are stored in the String array.Based on its length all file names are loaded into the JList. It's easy to display an array or vector of objects, using a JList constructor. AJList is a component that allows the user to select one or more objects from a list.

Java Swing List for display files names:

import java.io.*; import java.net.*; import java.util.*; import java.sql.*; public class MainServer extends javax.swing.JFrame implements Runnable { ServerSocket ss=null; Socket s=null; Vector v1=new Vector(); String fStr; public MainServer() { initComponents(); setLocation(100,100); setSize(530,460); } private void initComponents() { jPanel1 = new javax.swing.JPanel(); list = new java.awt.List(); start = new java.awt.Button(); jLabel1 = new javax.swing.JLabel(); getContentPane().setLayout(null); setTitle("MainServer"); addWindowListener(new java.awt.event.WindowAdapter() { public void windowClosing(java.awt.event.WindowEvent evt) { exitForm(evt); } }); jPanel1.setLayout(null); jPanel1.setBackground(new java.awt.Color(0, 153, 153)); jPanel1.add(list); list.setBounds(90, 120, 340, 190); start.setBackground(new java.awt.Color(204, 204, 204)); start.setFont(new java.awt.Font("Dialog", 0, 24)); start.setForeground(new java.awt.Color(0, 0, 0)); start.setLabel("List"); start.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { startActionPerformed(evt); } }); jPanel1.add(start); start.setBounds(200, 340, 110, 40); jLabel1.setFont(new java.awt.Font("Dialog", 1, 36)); jLabel1.setForeground(new java.awt.Color(0, 255, 255)); jLabel1.setText("List of Files"); jPanel1.add(jLabel1); jLabel1.setBounds(150, 40, 210, 40); getContentPane().add(jPanel1); jPanel1.setBounds(10, 10, 500, 410); pack(); } private void startActionPerformed(java.awt.event.ActionEvent evt) { start.setEnabled(false); try{ File allcerfiles=new File("G:/AIRVOD/movies"); String allfiles[]=allcerfiles.list(); String cerfile=""; for(int i=0;i

Sample ScreenShot:

SLogix Student Projects

⇓Student Projects⇓
⇑Student Projects⇑