1

As you know if you doble click a file, example a txt. It would launch notepad with the text file.

Is there any way I can do the same with my program that is like a txt file editor.

The only thing that I need to do when open by that way, is that a jTextArea is filled with the file location.

import otra.ReadFile;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.io.File;
import java.io.IOException;
import javax.swing.DefaultListModel;
import javax.swing.filechooser.FileNameExtensionFilter;
import otra.WriteFile;

public class Main extends javax.swing.JFrame {

    String startup = "C:\\";
    boolean puede = false;

    public Main() {
        initComponents();
        this.setLocationRelativeTo(null);
        this.setResizable(false);
        this.setTitle("Bot");
        FileNameExtensionFilter filter = new FileNameExtensionFilter("TEXT FILES", "txt", "text");
        jFileChooser1.setFileFilter(filter);
    }
private void initComponents() {

        jFileChooser1 = new javax.swing.JFileChooser();
        jButton1 = new javax.swing.JButton();
        jTextField1 = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        jButton2 = new javax.swing.JButton();
        jComboBox1 = new javax.swing.JComboBox<>();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jButton1.setText("Start");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });
        getContentPane().add(jButton1, new org.netbeans.lib.awtextra.AbsoluteConstraints(167, 81, -1, -1));
        getContentPane().add(jTextField1, new org.netbeans.lib.awtextra.AbsoluteConstraints(28, 37, 344, -1));

        jLabel1.setText("Lugar");
        getContentPane().add(jLabel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(180, 10, -1, -1));

        jButton2.setText("Open");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });
        getContentPane().add(jButton2, new org.netbeans.lib.awtextra.AbsoluteConstraints(329, 0, -1, -1));

        jComboBox1.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "Selector", "Listado", "Editor", "Editor2.0" }));
        jComboBox1.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                jComboBox1ItemStateChanged(evt);
            }
        });
        getContentPane().add(jComboBox1, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 0, -1, -1));

        pack();
    }
}                    
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JComboBox<String> jComboBox1;
private javax.swing.JFileChooser jFileChooser1;
private javax.swing.JLabel jLabel1;
private javax.swing.JTextField jTextField1;  

So basicly when you douboe click a txt file, it is open by notepad!

So is there anyway I can open my program by doble clicking a txt and getting the file location?

HSuper
  • 36
  • 5
  • Does this answer your question? [Java application launcher](https://stackoverflow.com/questions/3319971/java-application-launcher) – lainatnavi Oct 16 '20 at 17:44
  • What do you mean exactly? You want to double click any file on your system and have its path passed to your program? Don't confuse that behavior with file associations. Those associations have nothing to do with Java -- that facility is provided by your OS. – MarsAtomic Oct 16 '20 at 17:46
  • Is like an exe opens a certain app, and a txt notepad but with the file location – HSuper Oct 16 '20 at 17:49
  • you need to be able to take a path to a file as an argument. if you examine the file associations its like `path/to/exec %filename%` so you would either need the Java application launcher to have a simple `path/to/exec` or figure out how to add `path/to/java.exe -any.vm.flags -jar path/to/jar path/to/file` – JoSSte Oct 16 '20 at 18:27
  • so bassicly you need to doble-click on your txt file and open your program? and also get the file location were it was doble-clicked from(your question is a bit confusing, but I think I know what are you talking about(I think that I don't know how)) – Holis Oct 16 '20 at 18:29
  • Holis: yes is like you can open notepad from a .exe or a txt file, JoSSte yea I need to be able to get the path of the file when is opened from a txt. – HSuper Oct 16 '20 at 18:32
  • [How to open user system preferred editor for given file?](https://stackoverflow.com/questions/526037/how-to-open-user-system-preferred-editor-for-given-file) – Gilbert Le Blanc Oct 16 '20 at 20:15

0 Answers0