-2

UPDATED: I think the issue might be that I have not added the: addActionListener(this) to the button, but the reason is because it was dragged and dropped. Had I done the GUI declaration everything would have been made in order, yet, I dont know how to fix that if I cannot even modify the code because it is placed there by Netbeans when using SWING. How can I fix that

======BELOW IS THE FULL CODE GENERATED BY SWING AND IT DID NOT INCLUDE THE ADD ACTION LISTENER QUESTION: WHERE CAN I ADD IT HERE BELOW ON PROPERTIES-CODE-WHERE SHOULD I ADD IT?THERE ARE A LOT OF OPTIONS pre-code, post-code, etc

  • To change this license header, choose License Headers in Project Properties.
  • To change this template file, choose Tools | Templates
  • and open the template in the editor. */

package gui;

import javax.swing.UIManager;

/** * * @author Natalochka */ public class Completo extends javax.swing.JFrame {

/**
 * Creates new form Completo
 */
public Completo() {
    initComponents();
}

/**
 * This method is called from within the constructor to initialize the form.
 * WARNING: Do NOT modify this code. The content of this method is always
 * regenerated by the Form Editor.
 */
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">                          
private void initComponents() {

    jLabel1 = new javax.swing.JLabel();
    jToolBar1 = new javax.swing.JToolBar();
    button_open = new javax.swing.JButton();
    jButton2 = new javax.swing.JButton();
    jButton1 = new javax.swing.JButton();
    jTabbedPane1 = new javax.swing.JTabbedPane();
    jPanel1 = new javax.swing.JPanel();
    jScrollPane1 = new javax.swing.JScrollPane();
    textAreaTab1 = new javax.swing.JTextArea();
    boton_findfile = new javax.swing.JButton();
    jButton5 = new javax.swing.JButton();
    jPanel4 = new javax.swing.JPanel();
    jTextField1 = new javax.swing.JTextField();
    jScrollPane2 = new javax.swing.JScrollPane();
    jTextArea2 = new javax.swing.JTextArea();
    jTextField2 = new javax.swing.JTextField();
    jTextField3 = new javax.swing.JTextField();
    jPanel2 = new javax.swing.JPanel();
    jPanel3 = new javax.swing.JPanel();
    jMenuBar1 = new javax.swing.JMenuBar();
    jMenu1 = new javax.swing.JMenu();
    jMenu2 = new javax.swing.JMenu();

    jLabel1.setText("jLabel1");

    setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
    setForeground(java.awt.Color.lightGray);

    jToolBar1.setBorder(javax.swing.BorderFactory.createEtchedBorder(java.awt.Color.lightGray, null));
    jToolBar1.setFloatable(false);
    jToolBar1.setRollover(true);

    button_open.setText("jButton3");
    button_open.setFocusable(false);
    button_open.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
    button_open.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
    jToolBar1.add(button_open);

    jButton2.setText("jButton2");
    jButton2.setFocusable(false);
    jButton2.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
    jButton2.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
    jToolBar1.add(jButton2);

    jButton1.setText("jButton1");
    jButton1.setFocusable(false);
    jButton1.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
    jButton1.setName("jButton1"); // NOI18N
    jButton1.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
    jToolBar1.add(jButton1);

    textAreaTab1.setColumns(20);
    textAreaTab1.setRows(5);
    jScrollPane1.setViewportView(textAreaTab1);

    boton_findfile.setIcon(new javax.swing.ImageIcon("C:\\Users\\Natalochka\\Documents\\NetBeansProjects\\SobreFiles\\faticons\\folder_explore.png")); // NOI18N
    boton_findfile.setToolTipText("");
    boton_findfile.setName("boton_findfile"); // NOI18N

    jButton5.setIcon(new javax.swing.ImageIcon("C:\\Users\\Natalochka\\Documents\\NetBeansProjects\\SobreFiles\\faticons\\book_picture.png")); // NOI18N
    jButton5.setToolTipText("");

    jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder("Text Tools"));

    jTextField1.setText("jTextField1");

    jTextArea2.setColumns(20);
    jTextArea2.setRows(5);
    jScrollPane2.setViewportView(jTextArea2);

    jTextField2.setText("jTextField2");

    jTextField3.setText("jTextField3");

    javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
    jPanel4.setLayout(jPanel4Layout);
    jPanel4Layout.setHorizontalGroup(
        jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(jPanel4Layout.createSequentialGroup()
            .addContainerGap()
            .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel4Layout.createSequentialGroup()
                    .addGap(62, 62, 62)
                    .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGap(45, 45, 45))
                .addComponent(jScrollPane2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addContainerGap())
    );
    jPanel4Layout.setVerticalGroup(
        jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(jPanel4Layout.createSequentialGroup()
            .addContainerGap()
            .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addGap(60, 60, 60)
            .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addGap(46, 46, 46)
            .addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addGap(70, 70, 70)
            .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addContainerGap())
    );

    javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
    jPanel1.setLayout(jPanel1Layout);
    jPanel1Layout.setHorizontalGroup(
        jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(jPanel1Layout.createSequentialGroup()
            .addGap(349, 349, 349)
            .addComponent(boton_findfile)
            .addGap(18, 18, 18)
            .addComponent(jButton5)
            .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        .addGroup(jPanel1Layout.createSequentialGroup()
            .addGap(40, 40, 40)
            .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 43, Short.MAX_VALUE)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 593, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addGap(70, 70, 70))
    );
    jPanel1Layout.setVerticalGroup(
        jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(jPanel1Layout.createSequentialGroup()
            .addGap(69, 69, 69)
            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 383, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(boton_findfile)
                .addComponent(jButton5))
            .addContainerGap(43, Short.MAX_VALUE))
    );

    jPanel1Layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {jPanel4, jScrollPane1});

    boton_findfile.getAccessibleContext().setAccessibleName("boton_findfile");

    jTabbedPane1.addTab("tab1", jPanel1);

    javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
    jPanel2.setLayout(jPanel2Layout);
    jPanel2Layout.setHorizontalGroup(
        jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGap(0, 944, Short.MAX_VALUE)
    );
    jPanel2Layout.setVerticalGroup(
        jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGap(0, 547, Short.MAX_VALUE)
    );

    jTabbedPane1.addTab("tab2", jPanel2);

    javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
    jPanel3.setLayout(jPanel3Layout);
    jPanel3Layout.setHorizontalGroup(
        jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGap(0, 944, Short.MAX_VALUE)
    );
    jPanel3Layout.setVerticalGroup(
        jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGap(0, 547, Short.MAX_VALUE)
    );

    jTabbedPane1.addTab("tab3", jPanel3);

    jMenu1.setText("File");
    jMenuBar1.add(jMenu1);

    jMenu2.setText("Edit");
    jMenuBar1.add(jMenu2);

    setJMenuBar(jMenuBar1);

    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(
        layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(layout.createSequentialGroup()
            .addGap(351, 351, 351)
            .addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 949, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        .addComponent(jToolBar1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
    );
    layout.setVerticalGroup(
        layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(layout.createSequentialGroup()
            .addComponent(jToolBar1, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addGap(41, 41, 41)
            .addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 575, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addContainerGap(76, Short.MAX_VALUE))
    );

    pack();
}// </editor-fold>                        

/**
 * @param args the command line arguments
 */


// Variables declaration - do not modify                     
public javax.swing.JButton boton_findfile;
private javax.swing.JButton button_open;
public javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JButton jButton5;
private javax.swing.JLabel jLabel1;
private javax.swing.JMenu jMenu1;
private javax.swing.JMenu jMenu2;
private javax.swing.JMenuBar jMenuBar1;
private javax.swing.JPanel jPanel1;
private javax.swing.JPanel jPanel2;
private javax.swing.JPanel jPanel3;
private javax.swing.JPanel jPanel4;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JScrollPane jScrollPane2;
private javax.swing.JTabbedPane jTabbedPane1;
private javax.swing.JTextArea jTextArea2;
private javax.swing.JTextField jTextField1;
private javax.swing.JTextField jTextField2;
private javax.swing.JTextField jTextField3;
private javax.swing.JToolBar jToolBar1;
public javax.swing.JTextArea textAreaTab1;
// End of variables declaration                   

}

  • Konrad, did you edit anything? I cant see any change. – Johny be good Dec 21 '13 at 22:12
  • You're not showing us which class those methods are part of, and how and where the listener is added to the button, which is the crucial part. – JB Nizet Dec 21 '13 at 22:36
  • Exactly you hit the nail, the issue is that the listener is not added to the button, but I am trying to figure out how since I created the button using the drag and drop. That is the key core issue. – Johny be good Dec 21 '13 at 22:51
  • I sure guess the wysiwyg editor created a field for your button. Add the listener just like you would if you wrote the code by yourself (which I think you should do). – JB Nizet Dec 21 '13 at 22:55
  • but the editor when it creates the button it does not let you modify the code in there. Yes, I am beginning to hate the wysiwyg but..creating all interfaces for all the tabs can be a nightmare to do it by hand. – Johny be good Dec 21 '13 at 23:03

1 Answers1

0
public Completo() {
    initComponents();
    this.button_open.addActionListener(new ActionListener() {
        ...
    });
}
JB Nizet
  • 678,734
  • 91
  • 1,224
  • 1,255
  • ouais, merci bien. When I do that, which is correct, it asks me to implement all the abstract methods, yes, I am familiar with it, but it rolls them out on the GUI file and I should not have the code of action performed there, I have it on the other file. How do I solve that? – Johny be good Dec 21 '13 at 23:13
  • `this.button_open.addActionListener(new TheActionListenerDefinedInAnotherClass());`. – JB Nizet Dec 21 '13 at 23:14
  • alright, superbe!, I learned to do the GUIs by code but I thought I would be faster to do it by drag and drop and I hate it because when you look at the extra code it is a nightmare. I dont know what is worse, to write all yourself or to try to look inside of what the editor has thrown in. – Johny be good Dec 21 '13 at 23:17