0

アイテムのリストを含む JTable と、いくつかのコンポーネントを含む JPanel があります。ボタンをクリックすると、JTable で選択された項目のすべての情報が JPanel に読み込まれます。最初はうまく動作しますが、ボタンをクリックすると Jpanel が空のコンポーネントで表示されます。

私のボタンをクリックしたときのコード:

jbtUpdateContract.addActionListener(new ActionListener(){
        public void actionPerformed(ActionEvent e)
        {
            Object contractID = getValueOfSelectedRow(contractTable, 0);
            Contract contract = contractTransaction.getContractByID(Integer.parseInt(contractID.toString()));

            //Create Jpanel to display information
            jplUpdateContractForm.removeAll();
            jplUpdateContractForm = createContractForm(contract);
            jplUpdateContractForm.revalidate();

            //Modify contract frame
            jfrmUpdateContract.getContentPane().add(jplUpdateContractForm,
                    BorderLayout.CENTER);
            jfrmUpdateContract.setSize(400, 300);
            jfrmUpdateContract.setVisible(true);
            jfrmUpdateContract.setResizable(false);
        }
    });

そして私のcreateContractForm機能:

public static JPanel createContractForm(Contract contract)
{
    JPanel jplContractForm = new JPanel(new SpringLayout());
    JLabel jlblAppointmentDate = new JLabel("Appointment date:", JLabel.TRAILING);
    jlblAppointmentDate.setName("jlblAppointmentDate");
    jplContractForm.add(jlblAppointmentDate);

    final JTextField jtxtAppointmentDate = new JTextField(15);
    jtxtAppointmentDate.setName("jtxtAppointmentDate");
    jtxtAppointmentDate.setText(contract.getAppointmentDate());
    jtxtAppointmentDate.setEditable(false);
    jtxtAppointmentDate.addMouseListener(appointmentDateMouseListener(jtxtAppointmentDate));        
    jlblAppointmentDate.setLabelFor(jtxtAppointmentDate);
    jplContractForm.add(jtxtAppointmentDate);
    jplContractForm.setOpaque(true);    

    //***Customer Cobobox
    JLabel jlblCustomer= new JLabel("Customer:", JLabel.TRAILING);
    jlblCustomer.setName("jlblCustomer");
    jplContractForm.add(jlblCustomer);

    final JComboBox  jcbxCustomer = new JComboBox();
    jcbxCustomer.setName("jcbxCustomer");
    //Load customers from DB to combobox
    Customer[] customers = customerTransaction.getAllCustomer();
    for(int i = 0; i < customers.length; i++)
        jcbxCustomer.addItem(customers[i]);
    System.out.println("----------CUSTOMER----------" + getIndexOfCustomerComboBoxItem(jcbxCustomer, contract.getCustomerSeq()));
    jcbxCustomer.setSelectedIndex(getIndexOfCustomerComboBoxItem(jcbxCustomer, contract.getCustomerSeq()));

    jlblCustomer.setLabelFor(jcbxCustomer);
    jplContractForm.add(jcbxCustomer);
    jplContractForm.setOpaque(true);
}

上記で説明したように、JPanel が空である理由を説明してください。

よろしく。

4

1 に答える 1