How to get filename in JTextArea in following case?

How to get filename in JTextArea in following case?

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
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

Ads









Related Tutorials/Questions & Answers:
How to get filename in JTextArea in following case?
how to get following output
Advertisements
how to get following output
how to get following answer in turbo c program
jTextArea
jtextarea
jtextarea
jtextarea
How To Fetch Data From Database Into JTextArea
Java get Filename without Extension
jTextArea
how to compare text in two jTextarea
how to send the content of jtextarea from netbeans IDE to webpage's textarea in java
how can i display a pdf file in a jtextarea
how to print the following pattern
ModuleNotFoundError: No module named 'cases'
How to print the following pattern in java?
How to resolve this error The filename, directory name, or volume label syntax is incorrect
how to add a update button in the following jsp
error occured in following page ... how to resolve it?
how to get UIView by tag
How to get Button Id ?
How to access the following tag from xml to jsp
JTextfields working with JTextArea
how to get radio value
AutoCompleteField using JTextArea
ModuleNotFoundError: No module named 'pytest-cases'
How to get project path
How to get project path
How to get Java SDK
How to get involved

Ads