Results 1 to 3 of 3
  1. #1
    Zuraima is offline Member
    Join Date
    Aug 2010
    Posts
    2
    Rep Power
    0

    Unhappy MouseClick in table of Search and To see previes record

    I am trying to to connect table Search Group and Add a new Group. Like when I am searching for grouo I can mouseClick and have to appear all the record but I am stuck
    And I really need a big help


    I am going to send at first FormSearchGroup and after FromAddGroup

    FormSearchGroup


    package securitysystem;

    import business.Group;
    import database.GroupDAO;
    import java.util.ArrayList;
    import javax.swing.JPanel;
    import javax.swing.table.DefaultTableModel;
    import securitysystem.FormAddGroup;
    import javax.swing.JDesktopPane;
    import javax.swing.DefaultComboBoxModel;


    /**
    *
    * @author user
    */
    public class FormSearchGroup extends javax.swing.JInternalFrame {
    //private Object listGroup;

    /** Creates new form FormSearchUser */
    public FormSearchGroup() {
    initComponents();
    tblGroup.setModel(model);
    model.addColumn("Id");
    model.addColumn("Name");
    tblGroup.setVisible(true);


    }



    /** 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() {

    lblName = new javax.swing.JLabel();
    txtName = new javax.swing.JTextField();
    btnSearch = new javax.swing.JButton();
    jScrollPane1 = new javax.swing.JScrollPane();
    tblGroup = new javax.swing.JTable(){ public boolean isCellEditable(int rowIndex, int columnIndex) {
    return false;
    } };


    setClosable(true);
    setMaximizable(true);
    setResizable(true);
    org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(s ecuritysystem.SecuritySystemApp.class).getContext( ).getResourceMap(FormSearchGroup.class);
    setTitle(resourceMap.getString("Form.title")); // NOI18N
    setName("Form"); // NOI18N
    getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

    lblName.setText(resourceMap.getString("lblName.tex t")); // NOI18N
    lblName.setName("lblName"); // NOI18N
    getContentPane().add(lblName, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 30, -1, -1));

    txtName.setText(resourceMap.getString("txtName.tex t")); // NOI18N
    txtName.setName("txtName"); // NOI18N
    getContentPane().add(txtName, new org.netbeans.lib.awtextra.AbsoluteConstraints(60, 30, 140, -1));

    btnSearch.setText(resourceMap.getString("btnSearch .text")); // NOI18N
    btnSearch.setName("btnSearch"); // NOI18N
    btnSearch.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(java.awt.event.ActionEvent evt) {
    btnSearchActionPerformed(evt);
    }
    });
    getContentPane().add(btnSearch, new org.netbeans.lib.awtextra.AbsoluteConstraints(510, 50, -1, -1));

    jScrollPane1.setName("jScrollPane1"); // NOI18N

    tblGroup.setModel(new javax.swing.table.DefaultTableModel(
    new Object [][] {
    {null, null},
    {null, null},
    {null, null},
    {null, null},
    {null, null},
    {null, null}
    },
    new String [] {
    "Id", "Name"
    }
    ));
    tblGroup.setName("tblGroup"); // NOI18N
    tblGroup.addMouseListener(new java.awt.event.MouseAdapter() {
    public void mouseClicked(java.awt.event.MouseEvent evt) {
    tblGroupMouseClicked(evt);
    }
    });
    jScrollPane1.setViewportView(tblGroup);
    tblGroup.getColumnModel().getColumn(0).setHeaderVa lue(resourceMap.getString("tblGroup.columnModel.ti tle0")); // NOI18N
    tblGroup.getColumnModel().getColumn(1).setHeaderVa lue(resourceMap.getString("tblGroup.columnModel.ti tle1")); // NOI18N

    getContentPane().add(jScrollPane1, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 90, 560, 240));

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

    private void btnSearchActionPerformed(java.awt.event.ActionEven t evt) {
    //int groupid = Integer.parseInt(txtGroupid.getText());
    String name = txtName.getText();




    GroupDAO gDAO = new GroupDAO();
    ArrayList<Group> groups = gDAO.search(name);
    for (int i=0; i<groups.size(); i++){
    Group g = groups.get(i);
    model.addRow(new Object[]{new Integer(g.getGroupId()), g.getName()});
    }
    }

    private void tblGroupMouseClicked(java.awt.event.MouseEvent evt) {
    // TODO add your handling code here:

    // int pos = tblSearchAgent.getSelectedRow();
    // Invoice inv = (Invoice)listInvoices.get(pos);
    if (evt.getClickCount() == 2){
    int posGroup = tblGroup.getSelectedRow();
    Group g = (Group)listGroups.get(posGroup);
    FormAddGroup formAddGroup = new FormAddGroup();
    formAddGroup.setGroup(g);
    formAddGroup.setFormSearchGroup(this);
    mainPanel.add(formAddGroup);
    formAddGroup.setVisible(true);

    }

    //FormManageInvoice formManagerInvoice = new FormManageInvoice(mainPanel);
    //formManagerInvoice.setInvoice(inv);
    //mainPanel.add(formManagerInvoice); //
    //formManagerInvoice.setVisible(true); //

    }


    // Variables declaration - do not modify
    private javax.swing.JButton btnSearch;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JLabel lblName;
    private javax.swing.JTable tblGroup;
    private javax.swing.JTextField txtName;
    // End of variables declaration

    DefaultTableModel model = new DefaultTableModel();

    private DefaultComboBoxModel modelGroup = new DefaultComboBoxModel();
    private ArrayList<Group> listGroups;


    public void fillComboGoup(){
    tblGroup.setModel(model);
    modelGroup.removeAllElements();
    GroupDAO gDAO = new GroupDAO();
    listGroups = gDAO.search( "");
    for (int i=0; i<listGroups.size();i++) {
    Group g = (Group)listGroups.get(i);
    String name = g.getName();
    modelGroup.addElement(name);

    }


    }}
    Last edited by Zuraima; 08-06-2010 at 12:20 AM.

  2. #2
    Zuraima is offline Member
    Join Date
    Aug 2010
    Posts
    2
    Rep Power
    0

    Default Continue {part 2 FormAddGroup

    package securitysystem;

    import business.Group;
    import database.GroupDAO;

    import javax.swing.JOptionPane;

    /**
    *
    * @author user
    */
    public class FormAddGroup extends javax.swing.JInternalFrame {

    /** Creates new form FormAddGroup */
    public FormAddGroup() {
    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() {

    lblName = new javax.swing.JLabel();
    txtName = new javax.swing.JTextField();
    btnAddNewGroup = new javax.swing.JButton();
    btnClose = new javax.swing.JButton();
    lblGroup = new javax.swing.JLabel();
    txtGroup = new javax.swing.JTextField();

    setClosable(true);
    setIconifiable(true);
    setMaximizable(true);
    setResizable(true);
    org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(s ecuritysystem.SecuritySystemApp.class).getContext( ).getResourceMap(FormAddGroup.class);
    setTitle(resourceMap.getString("Form.title")); // NOI18N
    setName("Form"); // NOI18N

    lblName.setText(resourceMap.getString("lblName.tex t")); // NOI18N
    lblName.setName("lblName"); // NOI18N

    txtName.setText(resourceMap.getString("txtName.tex t")); // NOI18N
    txtName.setName("txtName"); // NOI18N

    btnAddNewGroup.setText(resourceMap.getString("btnA ddNewGroup.text")); // NOI18N
    btnAddNewGroup.setName("btnAddNewGroup"); // NOI18N
    btnAddNewGroup.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(java.awt.event.ActionEvent evt) {
    btnAddNewGroupActionPerformed(evt);
    }
    });

    btnClose.setText(resourceMap.getString("btnClose.t ext")); // NOI18N
    btnClose.setName("btnClose"); // NOI18N
    btnClose.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(java.awt.event.ActionEvent evt) {
    btnCloseActionPerformed(evt);
    }
    });

    lblGroup.setText(resourceMap.getString("lblGroup.t ext")); // NOI18N
    lblGroup.setName("lblGroup"); // NOI18N

    txtGroup.setText(resourceMap.getString("txtGroup.t ext")); // NOI18N
    txtGroup.setName("txtGroup"); // NOI18N

    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(31, 31, 31)
    .addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.LEADING)
    .addGroup(javax.swing.GroupLayout.Alignment.TRAILI NG, layout.createSequentialGroup()
    .addComponent(btnAddNewGroup)
    .addGap(32, 32, 32)
    .addComponent(btnClose))
    .addGroup(layout.createSequentialGroup()
    .addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.TRAILING)
    .addComponent(lblName)
    .addComponent(lblGroup))
    .addGap(18, 18, 18)
    .addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.LEADING)
    .addComponent(txtName, javax.swing.GroupLayout.PREFERRED_SIZE, 229, javax.swing.GroupLayout.PREFERRED_SIZE)
    .addComponent(txtGroup, javax.swing.GroupLayout.PREFERRED_SIZE, 62, javax.swing.GroupLayout.PREFERRED_SIZE))))
    .addContainerGap(74, Short.MAX_VALUE))
    );
    layout.setVerticalGroup(
    layout.createParallelGroup(javax.swing.GroupLayout .Alignment.LEADING)
    .addGroup(layout.createSequentialGroup()
    .addGap(14, 14, 14)
    .addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.BASELINE)
    .addComponent(lblGroup)
    .addComponent(txtGroup, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
    .addPreferredGap(javax.swing.LayoutStyle.Component Placement.RELATED)
    .addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.BASELINE)
    .addComponent(txtName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
    .addComponent(lblName))
    .addGap(18, 18, 18)
    .addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.BASELINE)
    .addComponent(btnAddNewGroup)
    .addComponent(btnClose))
    .addContainerGap(23, Short.MAX_VALUE))
    );

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

    private void btnAddNewGroupActionPerformed(java.awt.event.Actio nEvent evt) {

    //int groupid= Integer.parseInt(txtGroup.getText()) ;
    String groupName= txtName.getText();




    Group group = new Group();
    group.setName(groupName);
    GroupDAO gDAO = new GroupDAO();
    String result = gDAO.addNewGroup(group);

    JOptionPane.showMessageDialog(null,result, "Result",JOptionPane.INFORMATION_MESSAGE);
    }

    private void btnCloseActionPerformed(java.awt.event.ActionEvent evt) {
    dispose();
    }


    // Variables declaration - do not modify
    private javax.swing.JButton btnAddNewGroup;
    private javax.swing.JButton btnClose;
    private javax.swing.JLabel lblGroup;
    private javax.swing.JLabel lblName;
    private javax.swing.JTextField txtGroup;
    private javax.swing.JTextField txtName;
    // End of variables declaration



    }

  3. #3
    C++
    C++ is offline Member
    Join Date
    Aug 2010
    Posts
    1
    Rep Power
    0

    Default

    lmfao @

    new Object [][] {
    {null, null},
    {null, null},
    {null, null},
    {null, null},
    {null, null},
    {null, null}
    },

Similar Threads

  1. I want to add, search, edit, delete record of employee
    By jacob.pham in forum New To Java
    Replies: 2
    Last Post: 07-16-2010, 07:22 AM
  2. How To Lissen to MouseClick on Combobox.?
    By ocean in forum New To Java
    Replies: 1
    Last Post: 12-04-2009, 08:06 AM
  3. Replies: 3
    Last Post: 03-26-2009, 08:35 AM
  4. Replies: 0
    Last Post: 04-01-2008, 11:43 AM
  5. Replies: 0
    Last Post: 09-28-2007, 02:01 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
  •