Results 1 to 8 of 8
- 07-24-2011, 03:58 PM #1
Member
- Join Date
- May 2011
- Posts
- 20
- Rep Power
- 0
Showing the content of a file and show in a text area
Hi,
can anybody help me
How can i create a frame where a button will browse for a file and will show the content of the file in a text area,
so basically there will be a button,TextBox or something(will show the path of the file choose) and a text area(will show the content of the file),
Can anybody help me in this...
-
Probably.
Is this a Swing GUI? AWT? Other?How can i create a frame where a button will browse for a file and will show the content of the file in a text area, so basically there will be a button,TextBox or something(will show the path of the file choose) and a text area(will show the content of the file)
Where are you stuck? If Swing, do you know how to create a JFrame and a JButton and how to add an ActionListener to the JButton? Do you know how to add a JTextArea to your GUI using layout managers? Do you know how to use a JFileChooser to select a file? Do you know how to read a file's text into a JTextArea?
So if you can tell us specifically where you're stuck, we can probably give you specific advice. Right now, I'm going to recommend that you check out these terms above in the Swing tutorials.
Luck!
- 07-24-2011, 04:08 PM #3
For selecting a file JFileChooser would probably be the easiest.
Like Fubarable said, be more specific so we can help you more.- Use [code][/code] tags when posting code. That way people don't want to stab their eyes out when trying to help you.
- +Rep people for helpful posts.
- 07-24-2011, 05:01 PM #4
If that's all that has to be done, a JFileChooser with an accessory component to display the selected file's content is all that's needed. Go through the tutorial linked from the JFileChooser API.
db
- 07-24-2011, 05:01 PM #5
Member
- Join Date
- May 2011
- Posts
- 20
- Rep Power
- 0
Ok.....
i want to create a button with the name "Browse" and there will be a textbox on the leftside of the button, upon clicking this "browse button" i need to open "file chooser" from where i can select a file..on selecting this specific file , the path will be shown on the "textbox" , there will be a text area which will show the content of the selecting file..
Using swing....i have to do...
- 07-24-2011, 05:05 PM #6
Ok, then you need to look at Swing tutorials and API. Use JFileChooser to get your file and follow JosAH's advice.
- Use [code][/code] tags when posting code. That way people don't want to stab their eyes out when trying to help you.
- +Rep people for helpful posts.
- 07-24-2011, 05:15 PM #7
Member
- Join Date
- May 2011
- Posts
- 20
- Rep Power
- 0
Here is i am trying to write some code...
my target is when button will be clicked Filechooser will be opend and we can choose a file and can read the file and show in a text area in the same frame...
Java Code:import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.*; public class ButtonAction { public static void main(String[] args) { final JFrame frame1 = new JFrame("JAVA"); frame1.setSize(600,600); frame1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JButton button = new JButton(" Browse a file"); //Add action listener to button button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { //Execute when button is pressed //FileChooser fc = new JFileChooser(); //fc.showOpenDialog(frame); } }); frame1.getContentPane().add(button); frame1.pack(); frame1.setVisible(true); } }Last edited by JosAH; 07-24-2011 at 05:52 PM. Reason: Added [code] ... [/code] tags
-
Try to get that code out of the main method and into a proper object. You'll want to have a JTextArea as a non-static field of the class, you'll want to try to use your JFileChooser rather than comment out the code -- give it a try, you really can't break anything, and you'll want to use code tags when posting code in the forum so we can read it. Please check out the link in my signature for more on how to use code tags.
Similar Threads
-
Reading from a text file, then writing back to Text Area in Reverse
By medic642 in forum New To JavaReplies: 8Last Post: 07-17-2011, 02:38 PM -
show text file to textArea
By louboulos in forum New To JavaReplies: 14Last Post: 06-12-2011, 01:16 PM -
sorting read data from a file into text area by highest score
By Paperkut in forum AWT / SwingReplies: 2Last Post: 04-27-2011, 04:09 PM -
Applet program to open a text file and display the content in text area
By bitse in forum Java AppletsReplies: 0Last Post: 12-09-2010, 05:56 PM -
How to get the content of text file to write in JTextArea?
By realahmed8 in forum New To JavaReplies: 10Last Post: 05-24-2010, 08:25 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks