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?