0

列数とデータ型に基づいて動的テーブルを作成したいと考えています。JTextField問題は、JComboBoxジェネリック型リストから要素を取得したいときです。別のジェネリック型から反復する必要がありますが、Table 型などの 1 つのジェネリック型に追加します。主な問題は方法にあると思いますcretaeTable()

public class Table {


    public String getColumnName() {
        return columnName;
    }
    public void setColumnName(String columnName) {
        this.columnName = columnName;
    }
    public String getDatatype() {
        return datatype;
    }
    public void setDatatype(String datatype) {
        this.datatype = datatype;
    }
    private String columnName;
    private String datatype;

}

            List<JTextField> fields = new ArrayList<JTextField>();
            List<JComboBox> combos = new ArrayList<JComboBox>();

        // adding elemet 

        public void addNewElements(ActionEvent evt) {
                System.out.println("txtInputColNum.getText():: " +txtNumColumn.getText());
                if(!(txtNumColumn.getText()== null || txtNumColumn.getText().equals("")))   {
                    if(Integer.parseInt(txtNumColumn.getText())>0){
                        noOfColumn =Integer.parseInt(txtNumColumn.getText());
                        int txtFieldX= 10;
                        int comboFieldX = 120;

                        for (int i= 0; i < noOfColumn; i++){ 
                             JTextField newJTextField = new JTextField("",4);
                             newJTextField.setBounds(txtFieldX, 60, 100, 25);
                             String course[] = {"VARCHAR2","NUMBER","DATE"};
                             JComboBox combo = new JComboBox(course);
                             combo.setBounds(comboFieldX, 60, 100, 25);
                             fields.add(newJTextField);

                            this.add(newJTextField);                    
                            this.add(combo);
                            combos.add(combo);
                            txtFieldX = txtFieldX+250;
                            comboFieldX = comboFieldX+250;
                        }

                    }

                }   

                this.repaint();
                this.validate();
            }


    // call createTable method


        public void createTable(ActionEvent evt) {
            List<Table> tabList = new ArrayList<Table>();

            System.out.println("fields "+ fields.size());
            for(JTextField textField :fields){
                Table table = new Table();
                //System.out.println("textField:: "+ textField.getText());          
                table.setColumnName(textField.getText().toString());
                tabList.add(table);
            }

            for(JComboBox comboField :combos){
                Table table2 = new Table();
                System.out.println("comboField:: "+ comboField.getSelectedItem().toString());           
                table2.setDatatype(comboField.getSelectedItem().toString());
                tabList.add(table2);
            }


            for(Table tableModel:tabList){
                System.out.println("getColumnName "+ tableModel.getColumnName());
                System.out.println("getDatatype "+ tableModel.getDatatype());
            }
        }
4

0 に答える 0