将JTable中的数据添加到另一个

时间:2016-05-02 12:59:57

标签: java swing jtable

我有一个显示问题列表的JTable。 我想要做的是当我点击列表视图中的一个问题时,它将被添加到另一个JTable中(并且问题仍然存在于第一个JTable中)。 我当然必须在JTable上添加一个click事件,但在我知道该怎么做之后。

The result of the execution of the program

    List<Question> questions=new ArrayList<>();
    List<Question> questions2=new ArrayList<>(); 
    table_1 = new JTable();
    scrollPane_1.setViewportView(table_1);

    table = new JTable();
    scrollPane.setViewportView(table);
    setLayout(groupLayout);
    initDataBindings();

}
protected void initDataBindings() {
    JTableBinding<Question, List<Question>, JTable> jTableBinding = SwingBindings.createJTableBinding(UpdateStrategy.READ, questions, table);
    //
    BeanProperty<Question, String> questionBeanProperty = BeanProperty.create("contenu");
    jTableBinding.addColumnBinding(questionBeanProperty).setColumnName("Contenu");
    //
    BeanProperty<Question, Collection<Reponse>> questionBeanProperty_1 = BeanProperty.create("reponses");
    jTableBinding.addColumnBinding(questionBeanProperty_1).setColumnName("Les reponses");
    //
    BeanProperty<Question, String> questionBeanProperty_2 = BeanProperty.create("niveauDeDifficulte");
    jTableBinding.addColumnBinding(questionBeanProperty_2).setColumnName("Niveau de difficult\u00E9");
    //
    jTableBinding.bind();
}

1 个答案:

答案 0 :(得分:0)

您好,

    @Override
        public void mouseClicked(MouseEvent e) {
            questions2.add(questions.get(table.getSelectedRow()));

        }
    });