Menu

Don't know how to edit a set with a YTable.

Help
2007-09-30
2013-04-08
  • Guillermo Pollitzer

    Hello, and thanks in advance to my helper.
    I think i am doing a very simple and stupid question, i have spend hours tring to solve it with no success.
    I has writed my model, view and contrller. My view has a simple YTable related with a set of pojos in my model.
    When i run my app, the table shows the contents of my set of pojos in the model, buy i can't edit them.
    My question is: What have i do to be able to edit the set of pojos displayed in the YTable.
    I saw the code in the Customer example but i can't realize why it works there and not in my simple app.
    Here is my code:

    // the pojo java file
    public class MyPojo {
        String field1;
        String field2;
        public MyPojo(String field1, String field2) {
            super();
            this.field1 = field1;
            this.field2 = field2;
        }
        public String getField1() {
            return field1;
        }
        public void setField1(String field1) {
            this.field1 = field1;
        }
        public String getField2() {
            return field2;
        }
        public void setField2(String field2) {
            this.field2 = field2;
        }
    }

    //the model java file
    public class MyModel extends YModel {
        Set<MyPojo> pojos = new HashSet<MyPojo>();

        public Set<MyPojo> getPojos() {
            return pojos;
        }

        public void setPojos(Set<MyPojo> pojos) {
            this.pojos = pojos;
        }

        public MyModel() {
            super();
            this.pojos.add(new MyPojo("value1", "v1"));
            this.pojos.add(new MyPojo("value2", "v2"));
        }

    }
    // the view file
    public class MyView extends YFrame {
        private JScrollPane scrollPane;
        private YTable pojos;

        public MyView() {
            initGUI();
            YUIToolkit.guessMVCNames(this, true, null);
        }
        private void initGUI() {
            try {
                scrollPane = new JScrollPane();
                getContentPane().add(scrollPane, BorderLayout.CENTER);
                pojos = new YTable(new YColumn[] {
    new YColumn("field1", "field1"),
                        new YColumn("field2", "field2") });
                scrollPane.setViewportView(pojos);
                this.setSize(329, 131);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

    }

    public class MyController extends YController {
        MyView view = new MyView();
        MyModel model = new MyModel();
       
        MyController() {
            setUpMVC(model, view);
            view.pack();
            view.setVisible(true);
        }
        public static void main(String arg[]) {
            new MyController();
        }
        public void myViewClosing() {
            System.exit(0);
        }
    }

    Guillermo Pollitzer

     
    • Tomi Tuomainen

      Tomi Tuomainen - 2007-09-30

      Try table.setEditable(-1, -1, true); This affects the whole table (see javadoc of this method).

      Tomi

       

Log in to post a comment.