how to add an action listener


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 8 of 8

Thread: how to add an action listener

  1. #1
    Join Date
    Apr 2006
    Posts
    13

    how to add an action listener

    I have another problem .What I don't know is when i select a directory from a combobox I don't know how to add an action listener for displaying into a panel the directory that I select.Please help me

  2. #2
    Join Date
    Apr 2006
    Posts
    6
    From the API: http://java.sun.com/j2se/1.5.0/docs/...JComboBox.html

    Handling Events on a Combo Box

    Here's the code from ComboBoxDemo.java that registers and implements an action listener on the combo box:

    public class ComboBoxDemo ... implements ActionListener {
    . . .
    petList.addActionListener(this) {
    . . .
    public void actionPerformed(ActionEvent e) {
    JComboBox cb = (JComboBox)e.getSource();
    String petName = (String)cb.getSelectedItem();
    updateLabel(petName);
    }
    . . .
    }

    This action listener gets the newly selected item from the combo box, uses it to compute the name of an image file, and updates a label to display the image. The combo box fires an action event when the user selects an item from the combo box's menu. See How to Write an Action Listener http://java.sun.com/docs/books/tutor...nlistener.html (in the Creating a GUI with JFC/Swing trail), for general information about implementing action listeners.

    Combo boxes also generate item events, which are fired when any of the items' selection state changes. Only one item at a time can be selected in a combo box, so when the user makes a new selection the previously selected item becomes unselected. Thus two item events are fired each time the user selects a different item from the menu. If the user chooses the same item, no item events are fired. Use addItemListener to register an item listener on a combo box. How to Write an Item Listener http://java.sun.com/docs/books/tutor...mlistener.html (in the Creating a GUI with JFC/Swing trail) gives general information about implementing item listeners.

    Although JComboBox inherits methods to register listeners for low-level events focus, key, and mouse events, for example we recommend that you don't listen for low-level events on a combo box. Here's why: A combo box is a compound component it is comprised of two or more other components. The combo box itself fires high-level events such as action events. Its subcomponents fire low-level events such as mouse, key, and focus events. The low-level events and the subcomponent that fires them are look-and-feel-dependent. To avoid writing look-and-feel-dependent code, you should listen only for high-level events on a compound component such as a combo box. For information about events, including a discussion about high- and low-level events, refer to Writing Event Listeners http://java.sun.com/docs/books/tutor...nts/index.html (in the Creating a GUI with JFC/Swing trail).

    Good luck!

  3. #3
    Join Date
    Apr 2006
    Posts
    13

    JTree

    Great thanks for your help Iwill read what you sent me but now here is my problem:
    I have two panels and I want to see in every panel the local file system using a JTree .I've made that but the problem is that it is working only in a panel.I will send you my sorce code and plese run it and help me to find the error.Please !!!!!!!!!!!!!!!!!!!
    import java.io.*;
    import java.awt.*;
    import java.util.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.AbstractButton.*;
    import sun.awt.shell.*;
    import javax.swing.*;
    import javax.swing.event.*;
    import javax.swing.tree.*;
    class TotalCommander extends JFrame implements ActionListener, ListSelectionListener{

    private final int ITEM_PLAIN = 0; // Item types
    private final int ITEM_CHECK = 1;
    private final int ITEM_RADIO = 2;
    private JTextArea textA;
    private JMenuBar menuBar;
    private JMenu menuFiles;
    private JMenuItem menuFilesChangeAtributes;
    private JMenuItem menuFilesPack;
    private JMenuItem menuFilesUnpackSpecificFiles;
    private JMenuItem menuFilesTestArchive;
    private JMenuItem menuFilesCompareByContent;
    private JMenuItem menuFilesAssociateWith;
    private JMenuItem menuFilesProperties;
    private JMenuItem menuFilesCalculateOcuppiedSpace;
    private JMenuItem menuFilesPrint;
    private JMenuItem menuFilesSplitFile;
    private JMenuItem menuFilesCombineFile;
    private JMenuItem menuFilesEncodeFile;
    private JMenuItem menuFilesDecodeFile;
    private JMenuItem menuFilesQuit;
    private JMenuItem menuMarkSelectGroup;
    private JMenuItem menuMarkUnselectGroup;
    private JMenuItem menuMarkSelectAll;
    private JMenuItem menuMarkInvertSelection;
    private JMenuItem menuMarkRestoreSelection;
    private JMenuItem menuMarkCompareDirectories;
    private JMenuItem menuMarkMarkNewer;
    private JMenuItem menuMarkHideSameFiles;
    private JMenu menuMark;
    private JMenu menuCommands;
    private JMenu menuShow;
    private JMenu menuConfiguration;
    private JMenu menuStart;
    private JButton button,button1,button2,button3,button4,button5,button6,button7,button8,button9,button10;
    private JButton button11,button12,button13,button14,button15;
    private JFileChooser chooser;
    private JSplitPane splitPaneV;
    private JSplitPane splitPaneH;
    private JPanel panel3;
    private JPanel panel4,panel5,panel6,p;
    private JComboBox combo,combo1;
    private JTextPane dir,dir1;
    private File file,file1;
    private JTextField t1;
    private JTextArea t2;
    private JButton b;
    private JTree tree;
    private Vector drVector,Vector;
    private JList drList,C,D,E,F;
    //private JTextPane pan;
    protected static final ImageIcon ICON_COMPUTER = new ImageIcon("d:\\icon\\computer.gif");
    protected static final ImageIcon ICON_DISK = new ImageIcon("d:\\icon\\disk.gif");
    protected static final ImageIcon ICON_FOLDER = new ImageIcon(" d:\\icon\\folder.gif ");
    protected static final ImageIcon ICON_EXPANDEDFOLDER = new ImageIcon(" d:\\icon\\expandedfolder.gif ");
    public JTree m_tree,m_tree1;
    public DefaultTreeModel m_model,m_model1;
    public JTextField m_display,m_display1;

    public TotalCommander(){
    // super("Directories Tree");
    // setSize(100, 90);
    final String[] sList ={"C","D","E","F"};
    setTitle( "Total Commander Application" );
    setSize( 700, 700 );
    JScrollPane scrollPane = new JScrollPane();
    getContentPane().add( scrollPane,BorderLayout.CENTER );
    JPanel topPanel = new JPanel();
    topPanel.setLayout( new BorderLayout() );
    getContentPane().add( topPanel );
    createPanel1();
    createPanel2();
    splitPaneV = new JSplitPane( JSplitPane.VERTICAL_SPLIT );
    topPanel.add( splitPaneV, BorderLayout.CENTER );
    splitPaneH = new JSplitPane( JSplitPane.HORIZONTAL_SPLIT );
    splitPaneH.setLeftComponent( panel3 );
    splitPaneH.setRightComponent( panel4 );
    splitPaneV.setLeftComponent( splitPaneH );
    JPanel xAxisPanel = createXAxisPanel();
    topPanel.add( xAxisPanel, BorderLayout.NORTH );
    JPanel yAxisPanel =createYAxisPanel();
    topPanel.add(yAxisPanel,BorderLayout.SOUTH);
    menuBar = new JMenuBar();
    // Seteaza aceasta instanta ca fiind bara de meniu a aplicatiei
    setJMenuBar( menuBar );
    // Creeaza un meniu "File"
    menuFiles = new JMenu( "Files" );
    menuFiles.setMnemonic( 'F' );
    menuBar.add( menuFiles );
    menuMark=new JMenu( "Mark" );
    menuMark.setMnemonic('M');
    menuBar.add(menuMark);
    menuCommands=new JMenu( "Commands" );
    menuCommands.setMnemonic('C');
    menuBar.add(menuCommands);
    menuShow=new JMenu("Show");
    menuShow.setMnemonic('S');
    menuBar.add(menuShow);
    menuConfiguration=new JMenu("Configuration");
    menuConfiguration.setMnemonic('G');
    menuBar.add(menuConfiguration);
    menuStart=new JMenu("Start");
    menuStart.setMnemonic('J');
    menuBar.add(menuStart);
    menuFilesChangeAtributes=CreateMenuItem(menuFiles,ITEM_PLAIN,"Change Atributes",null, 'G', null );
    menuFilesQuit = CreateMenuItem( menuFiles, ITEM_PLAIN,"Quit", null,'x',"Exit the program" );
    menuMarkSelectGroup=CreateMenuItem(menuMark, ITEM_PLAIN, "Select Group", null, 'M', null);
    menuMarkUnselectGroup=CreateMenuItem(menuMark, ITEM_PLAIN, "Unselect Group", null, 'U', null);
    menuMarkSelectAll=CreateMenuItem(menuMark, ITEM_PLAIN, "Select All", null, 'A', null);
    menuMarkInvertSelection=CreateMenuItem(menuMark, ITEM_PLAIN, "Invert Selection", null, 'I', null);
    menuMarkRestoreSelection=CreateMenuItem(menuMark, ITEM_PLAIN, "Restore Selection", null, 'R', null);
    menuMarkCompareDirectories=CreateMenuItem(menuMark, ITEM_PLAIN, "Compare Directories", null, 'D', null);
    menuMarkMarkNewer=CreateMenuItem(menuMark, ITEM_PLAIN, "Mark Newer", null, 'N', null);
    menuMarkHideSameFiles=CreateMenuItem(menuMark, ITEM_PLAIN, "Hide Same Files", null, 'H', null);
    //Creeaza un dialog "file chooser"
    chooser=new JFileChooser();
    chooser.setCurrentDirectory(new File("."));
    }
    public JPanel createYAxisPanel(){
    JPanel panel1=new JPanel();
    panel1.setLayout(new BoxLayout(panel1, BoxLayout.X_AXIS));
    button9=new JButton("Wiew");
    button9.setToolTipText("wiew");
    panel1.add(button9);
    button10=new JButton("Edit");
    panel1.add(button10);
    button11=new JButton("Copy");
    panel1.add(button11);
    button12=new JButton("RenMov");
    panel1.add(button12);
    button13=new JButton("MkDir");
    panel1.add(button11);
    button14=new JButton("Delete");
    panel1.add(button14);
    button15=new JButton("Exit");
    panel1.add(button15);
    return panel1;
    }
    public JPanel createXAxisPanel()
    {
    JPanel panel = new JPanel();
    panel.setLayout( new BoxLayout( panel, BoxLayout.X_AXIS ) );
    ImageIcon image = new ImageIcon( "d:\\icon\\diskette.gif" );
    button=new JButton(image);
    button.setToolTipText("Reread Source");
    panel.add( button );
    ImageIcon image6 = new ImageIcon( "d:\\icon\\nukeicon[1].gif" );
    button1=new JButton(image6);
    button1.setToolTipText("CD Tree");
    panel.add(button1);
    ImageIcon image7 = new ImageIcon( "d:\\icon\\brief.gif" );
    button2=new JButton(image7);
    button2.setToolTipText("Brief");
    panel.add(button2);
    ImageIcon image8= new ImageIcon("d:\\icon\\full.gif");
    button3=new JButton(image8);
    button3.setToolTipText("Full");
    panel.add(button3);
    ImageIcon image4 = new ImageIcon( "d:\\icon\\directry.gif" );
    button4=new JButton(image4);
    button4.setToolTipText("Tree");
    panel.add(button4);
    ImageIcon image5=new ImageIcon("d:\\icon\\invert.gif");
    button5=new JButton(image5);
    button5.setToolTipText("Invert Selection");
    panel.add(button5);
    ImageIcon image2 = new ImageIcon( "d:\\icon\\ftp.gif" );
    button6=new JButton(image2);
    button6.setToolTipText("FTP Conect");
    panel.add(button6);
    ImageIcon image1 = new ImageIcon( "d:\\icon\\notepad.gif" );
    button7=new JButton(image1);
    button7.setToolTipText("Notepad");
    panel.add(button7);
    ImageIcon image3 = new ImageIcon( "d:\\icon\\winamp.gif" );
    button8=new JButton(image3);
    button8.setToolTipText("Winamp");
    panel.add(button8);
    return panel;
    }
    public void createPanel1()
    {
    final String[] sList ={"c:\\","d:\\","e:\\","f:\\"};
    combo = new JComboBox();
    // Populeaza lista ComboBox
    for( int iCtr = 0; iCtr < sList.length; iCtr++ )
    combo.addItem( sList[iCtr] );
    // Permite editarea
    combo.setEditable( true );
    combo.addActionListener( this );
    panel3 = new JPanel();
    panel3.setLayout( new BorderLayout() );
    panel3.setPreferredSize( new Dimension( 400, 100 ) );
    panel3.setMinimumSize( new Dimension( 100, 50 ) );
    panel3.add( combo,BorderLayout.NORTH);
    DefaultMutableTreeNode top = new DefaultMutableTreeNode(new IconData(ICON_COMPUTER, null, "Computer"));
    DefaultMutableTreeNode node;
    File[] roots = File.listRoots();
    for (int k=0; k<roots.length; k++)
    {
    node = new DefaultMutableTreeNode(new IconData(ICON_DISK, null, new FileNode(roots[k])));
    top.add(node);
    node.add( new DefaultMutableTreeNode(new Boolean(true)));
    }
    m_model = new DefaultTreeModel(top);
    m_tree = new JTree(m_model);
    m_tree.putClientProperty("JTree.lineStyle", "Angled");
    TreeCellRenderer renderer = new IconCellRenderer();
    m_tree.setCellRenderer(renderer);
    m_tree.addTreeExpansionListener(new DirExpansionListener());
    m_tree.addTreeSelectionListener(new DirSelectionListener());
    m_tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    m_tree.setShowsRootHandles(true);
    m_tree.setEditable(false);
    JScrollPane s = new JScrollPane();
    s.getViewport().add(m_tree);
    panel3.add(s, BorderLayout.CENTER);
    WindowListener wndCloser = new WindowAdapter()
    {
    public void windowClosing(WindowEvent e)
    {
    System.exit(0);
    }
    };
    addWindowListener(wndCloser);
    setVisible(true);
    combo.setBounds( 5, 5, 6, 2 );
    }

  4. #4
    Join Date
    Apr 2006
    Posts
    13

    JTree

    public void createPanel2()
    {
    combo = new JComboBox();
    combo.addItem("c:\\");
    combo.addItem("d:\\");
    combo.addItem("e:\\");
    combo.addItem("f:\\");
    combo.setEditable( true );
    combo.addActionListener( this );
    panel4 = new JPanel();
    panel4.setLayout( new BorderLayout() );
    panel4.setPreferredSize( new Dimension( 400, 100 ) );
    panel4.setMinimumSize( new Dimension( 100, 50 ) );
    panel4.add( combo,BorderLayout.NORTH);
    DefaultMutableTreeNode top = new DefaultMutableTreeNode(new IconData(ICON_COMPUTER, null, "Computer"));
    DefaultMutableTreeNode node;
    File[] roots = File.listRoots();
    for (int k=0; k<roots.length; k++)
    {
    node = new DefaultMutableTreeNode(new IconData(ICON_DISK, null, new FileNode(roots[k])));
    top.add(node);
    node.add( new DefaultMutableTreeNode(new Boolean(true)));
    }
    m_model = new DefaultTreeModel(top);
    m_tree = new JTree(m_model);
    m_tree.putClientProperty("JTree.lineStyle", "Angled");
    TreeCellRenderer renderer = new
    IconCellRenderer();
    m_tree.setCellRenderer(renderer);
    m_tree.addTreeExpansionListener(new
    DirExpansionListener());
    m_tree.addTreeSelectionListener(new
    DirSelectionListener());
    m_tree.getSelectionModel().setSelectionMode(
    TreeSelectionModel.SINGLE_TREE_SELECTION);
    m_tree.setShowsRootHandles(true);
    m_tree.setEditable(false);
    JScrollPane s = new JScrollPane();
    s.getViewport().add(m_tree);
    panel4.add(s, BorderLayout.CENTER);
    WindowListener wndCloser = new WindowAdapter()
    {
    public void windowClosing(WindowEvent e)
    {
    System.exit(0);
    }
    };
    addWindowListener(wndCloser);
    setVisible(true);
    combo.setBounds( 5, 5, 6, 2 );
    }
    public JMenuItem CreateMenuItem( JMenu menu, int iType,String sText, ImageIcon image,
    int acceleratorKey, String sToolTip )
    {
    // Creeaza optiunea meniului
    JMenuItem menuItem;
    switch( iType )
    {
    case ITEM_RADIO:
    menuItem = new JRadioButtonMenuItem();
    break;
    case ITEM_CHECK:
    menuItem = new JCheckBoxMenuItem();
    break;
    default:
    menuItem = new JMenuItem();
    break;
    }
    // Adauga textul optiunii
    menuItem.setText( sText );
    // Adauga imaginea (optional)
    if( image != null )
    menuItem.setIcon( image );
    // Adauga acceleratorul (combinatia de taste)
    if( acceleratorKey > 0 )
    menuItem.setMnemonic( acceleratorKey );
    // Adauga textul pentru "tool tip" (optional)
    if( sToolTip != null )
    menuItem.setToolTipText( sToolTip );
    // Adauga un obiect ascultator de evenimente pentru aceasta optiune a meniului
    menuItem.addActionListener( this );
    menu.add( menuItem );
    return menuItem;
    }
    DefaultMutableTreeNode getTreeNode(TreePath path)
    {
    return (DefaultMutableTreeNode)(path.getLastPathComponent());
    }

    FileNode getFileNode(DefaultMutableTreeNode node)
    {
    if (node == null)
    return null;

    Object obj = node.getUserObject();

    if (obj instanceof IconData)
    obj = ((IconData)obj).getObject();
    if (obj instanceof FileNode)
    return (FileNode)obj;
    else
    return null;

    }


    public void actionPerformed( ActionEvent event ){
    if (event.getSource()==combo){

    String q=(String)combo.getSelectedItem();
    if(q.compareTo("c:\\")==0){
    File tmp = new File(q);
    if (tmp.isDirectory());

    C.getSelectedValue();//panel4.add(C);
    }
    if(q.compareTo("d:\\")==0){
    File tmp1 = new File(q);
    if (tmp1.isDirectory());
    D.getSelectedValue();
    }

    }
    if (event.getSource()==menuFilesQuit)
    {
    System.exit(0);
    }
    if(event.getSource()==menuFilesChangeAtributes){
    JOptionPane dialog = new JOptionPane();
    dialog.showMessageDialog( this, "No files were selected",
    "Error", JOptionPane.ERROR_MESSAGE );

    }
    if(event.getSource()==menuMarkSelectGroup){
    JOptionPane dialog=new JOptionPane();
    dialog.showMessageDialog(this,"No files were selected","Error",JOptionPane.ERROR_MESSAGE);
    }
    }
    class DirExpansionListener implements TreeExpansionListener
    {
    public void treeExpanded(TreeExpansionEvent event)
    {
    final DefaultMutableTreeNode node = getTreeNode(event.getPath());

    final FileNode fnode = getFileNode(node);

    Thread runner = new Thread()
    {
    public void run()
    {
    if (fnode != null && fnode.expand(node))

    {
    Runnable runnable = new Runnable()
    {
    public void run()
    {
    m_model.reload(node);

    }
    };
    SwingUtilities.invokeLater(runnable);
    }
    }
    };
    runner.start();
    }

    public void treeCollapsed(TreeExpansionEvent event) {}
    }
    class DirSelectionListener
    implements TreeSelectionListener
    {
    public void valueChanged(TreeSelectionEvent event)
    {
    DefaultMutableTreeNode node = getTreeNode( event.getPath());

    FileNode fnode = getFileNode(node);
    if (fnode != null)
    m_display.setText(fnode.getFile(). getAbsolutePath());
    else
    m_display.setText("");
    }
    }
    public static void main( String args[] )
    {
    TotalCommander mainFrame = new TotalCommander();
    mainFrame.pack();
    mainFrame.setVisible( true );


    }
    public void valueChanged( ListSelectionEvent event )
    {}
    }
    class IconCellRenderer extends JLabel implements TreeCellRenderer
    {
    protected Color m_textSelectionColor;
    protected Color m_textNonSelectionColor;
    protected Color m_bkSelectionColor;
    protected Color m_bkNonSelectionColor;
    protected Color m_borderSelectionColor;

    protected boolean m_selected;

    public IconCellRenderer()
    {
    super();
    m_textSelectionColor = UIManager.getColor("Tree.selectionForeground");
    m_textNonSelectionColor = UIManager.getColor("Tree.textForeground");
    m_bkSelectionColor = UIManager.getColor("Tree.selectionBackground");
    m_bkNonSelectionColor = UIManager.getColor("Tree.textBackground");
    m_borderSelectionColor = UIManager.getColor("Tree.selectionBorderColor");
    setOpaque(false);
    }

    public Component getTreeCellRendererComponent(JTree tree,Object value,boolean sel,boolean expanded,boolean leaf,int row,boolean hasFocus)
    {
    DefaultMutableTreeNode node = (DefaultMutableTreeNode)value;

    Object obj = node.getUserObject();

    setText(obj.toString());

    if (obj instanceof Boolean)
    setText("Retrieving data...");

    if (obj instanceof IconData)
    {
    IconData idata = (IconData)obj;
    if (expanded)
    setIcon(idata.getExpandedIcon());
    else
    setIcon(idata.getIcon());
    }
    else
    setIcon(null);

    setFont(tree.getFont());
    setForeground(sel ? m_textSelectionColor :
    m_textNonSelectionColor);
    setBackground(sel ? m_bkSelectionColor :
    m_bkNonSelectionColor);
    m_selected = sel;
    return this;
    }
    public void paintComponent(Graphics g)
    {
    Color bColor = getBackground();
    Icon icon = getIcon();
    g.setColor(bColor);
    int offset = 0;
    if(icon != null && getText() != null)
    offset = (icon.getIconWidth() + getIconTextGap());
    g.fillRect(offset, 0, getWidth() - 1 - offset,
    getHeight() - 1);
    if (m_selected)
    {
    g.setColor(m_borderSelectionColor);
    g.drawRect(offset, 0, getWidth()-1-offset, getHeight()-1);
    }
    super.paintComponent(g);
    }
    }

  5. #5
    Join Date
    Apr 2006
    Posts
    13

    JTree

    class IconData
    {
    protected Icon m_icon;
    protected Icon m_expandedIcon;
    protected Object m_data;

    public IconData(Icon icon, Object data)
    {
    m_icon = icon;
    m_expandedIcon = null;
    m_data = data;
    }

    public IconData(Icon icon, Icon expandedIcon, Object data)
    {
    m_icon = icon;
    m_expandedIcon = expandedIcon;
    m_data = data;
    }

    public Icon getIcon()
    {
    return m_icon;
    }

    public Icon getExpandedIcon()
    {
    return m_expandedIcon!=null ? m_expandedIcon : m_icon;
    }

    public Object getObject()
    {
    return m_data;
    }

    public String toString()
    {
    return m_data.toString();
    }
    }

    class FileNode
    {
    protected File m_file;

    public FileNode(File file)
    {
    m_file = file;
    }

    public File getFile()
    {
    return m_file;
    }

    public String toString()
    {
    return m_file.getName().length() > 0 ? m_file.getName() :
    m_file.getPath();
    }

    public boolean expand(DefaultMutableTreeNode parent)
    {
    DefaultMutableTreeNode flag = (DefaultMutableTreeNode)parent.getFirstChild();
    if (flag==null) // No flag
    return false;
    Object obj = flag.getUserObject();
    if (!(obj instanceof Boolean))
    return false; // Already expanded

    parent.removeAllChildren(); // Remove Flag

    File[] files = listFiles();
    if (files == null)
    return true;

    Vector v = new Vector();

    for (int k=0; k<files.length; k++)
    {
    File f = files[k];
    if (!(f.isDirectory()))
    continue;

    FileNode newNode = new FileNode(f);
    boolean isAdded = false;
    for (int i=0; i<v.size(); i++)
    {
    FileNode nd = (FileNode)v.elementAt(i);
    if (newNode.compareTo(nd) < 0)
    {
    v.insertElementAt(newNode, i);
    isAdded = true;
    break;
    }
    }
    if (!isAdded)
    v.addElement(newNode);
    }

    for (int i=0; i<v.size(); i++)
    {
    FileNode nd = (FileNode)v.elementAt(i);
    IconData idata = new IconData(TotalCommander.ICON_FOLDER, TotalCommander.ICON_EXPANDEDFOLDER, nd);
    DefaultMutableTreeNode node = new DefaultMutableTreeNode(idata);
    parent.add(node);
    if (nd.hasSubDirs())
    node.add(new DefaultMutableTreeNode( new Boolean(true) ));
    }
    return true;
    }

    public boolean hasSubDirs()
    {
    File[] files = listFiles();
    if (files == null)
    return false;
    for (int k=0; k<files.length; k++)
    {
    if (files[k].isDirectory())
    return true;
    }
    return false;
    }
    public int compareTo(FileNode toCompare)
    {
    return m_file.getName().compareToIgnoreCase(
    toCompare.m_file.getName() );
    }

    protected File[] listFiles()
    {
    if (!m_file.isDirectory())
    return null;
    try
    {
    return m_file.listFiles();
    }
    catch (Exception ex)
    {
    JOptionPane.showMessageDialog(null, "Error reading directory "+m_file.getAbsolutePath(),"Warning", JOptionPane.WARNING_MESSAGE);
    return null;
    }
    }
    }

  6. #6
    Join Date
    Mar 2004
    Posts
    635
    use CODE tags!

  7. #7
    Join Date
    Apr 2006
    Posts
    13
    ok thanks

  8. #8
    Join Date
    Apr 2006
    Posts
    13
    please take a look at my source of totalcommander!!!!!!!!!:d
    for the moment it don't have all the functionality but run what i did for the moment.I don't know were it's wrong

Similar Threads

  1. Replies: 8
    Last Post: 04-11-2006, 08:40 AM
  2. Can't add action listener
    By vxfox05 in forum Java
    Replies: 3
    Last Post: 04-29-2005, 08:04 PM
  3. Cant get Action listener to work.
    By DrunkinP in forum Java
    Replies: 1
    Last Post: 03-31-2005, 03:16 PM
  4. Replies: 2
    Last Post: 06-27-2000, 10:29 AM
  5. Replies: 0
    Last Post: 06-11-2000, 08:29 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center