Results 1 to 3 of 3
  1. #1
    Join Date
    Aug 2011
    Location
    Gold Coast, Australia
    Posts
    3
    Rep Power
    0

    Default Help with using a jbutton actionlistener to open a text file

    Hey Guys,

    I've been building a contact editor GUI using Netbeans 7, and I'm stuck on how to open a text file with a button. I've searched around, but only found advice relating to jfilechooser. The text file contains all the entries submitted to the contact editor, and I don't need it to be opened within the GUI, just with notepad outside of the program.

    Any help is appreciated!

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,902
    Rep Power
    25

    Default Re: Help with using a jbutton actionlistener to open a text file

    how to open a text file with a button
    The button's action listener method would call a method in one of the following classes.
    with notepad outside of the program.
    Look at the Desktop class. It will ask the OS to provide the program to open a file.
    If you want to specify which program to use, see the Process and Runtime classes where you can specify the full ccommand line to be executed.

  3. #3
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,800
    Rep Power
    7

    Default Re: Help with using a jbutton actionlistener to open a text file

    Why do you need to open the file in Notepad? Why can't you display the file on a JTextArea or a JEditorPane?

    If you are determined to use Notepad then you can investigate Runtime.exec but make sure you google "pitfalls of runtime exec" or something similar.

Similar Threads

  1. open text document using JButton
    By coopc in forum New To Java
    Replies: 3
    Last Post: 05-04-2011, 01:02 AM
  2. JButton ActionListener problems
    By Fortu in forum New To Java
    Replies: 6
    Last Post: 02-05-2011, 05:20 PM
  3. Replies: 0
    Last Post: 12-09-2010, 06:56 PM
  4. text editor does not open file
    By globo in forum Advanced Java
    Replies: 2
    Last Post: 11-21-2010, 08:39 PM
  5. How correctly open text file?
    By artemff in forum CLDC and MIDP
    Replies: 3
    Last Post: 12-23-2009, 07:39 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
  •