Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Swing-AWT How to get filename in JTextArea in following case?

Have Programming Question? Ask it here!
 
 
 


HHH
How to get filename in JTextArea in following case?
1 Answer(s)      3 years and 7 months ago
Posted in : Swing AWT


Hi,

i'm trying to code a GUI in java,
the following code is working but the filenam is not displayed in the JTextArea, why?
[CODE]
 private void saveasdirectorybuttonActionPerformed(java.awt.event.ActionEvent evt) {

 JFileChooser fc = new JFileChooser();

          fc.setSelectedFile(new File("c:/Temp/anyFilename.txt") );
          fc.showSaveDialog(SOHJoinerUI);
          File curFile = fc.getSelectedFile();
          JTextAreaOutputDirectory.append(curFile.getName());
    }



Thank you

Advertisement
View Answers

January 18, 2011 at 12:13 PM


Hi Friend,

Try this:

import java.io.*;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
class FileName extends JFrame
{
    JTextArea JTextAreaOutputDirectory;
    JButton b;
    JScrollPane pane;
     FileName(){
     setLayout(null);
     JTextAreaOutputDirectory=new JTextArea(5,20);
     pane=new JScrollPane(JTextAreaOutputDirectory);
     b=new JButton("Open");
     pane.setBounds(10,10,200,80);
     b.setBounds(10,100,80,20);
     add(pane);
     add(b);
     setVisible(true);
     setSize(300,180);
     b.addActionListener(new ActionListener(){
         public void actionPerformed(ActionEvent e){
          JFileChooser fc = new JFileChooser();
          fc.showOpenDialog(null);
          File curFile = fc.getSelectedFile();
          JTextAreaOutputDirectory.append(curFile.getName());
         }
   });
    }
    public static void main(String[] args) 
    {
        new FileName();
    }
}

Thanks



Related Tutorials/Questions & Answers:
Advertisements
 

 

 

DMCA.com