Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/381.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
JavaFX表格列排序问题_Java_Javafx 2_Fxml - Fatal编程技术网

JavaFX表格列排序问题

JavaFX表格列排序问题,java,javafx-2,fxml,Java,Javafx 2,Fxml,我的程序显示一个包含3列的表。单击列的标题时,TableView的内容不会被排序 如果我通过查看列中的排序数据正确理解了这一点,那么我不需要执行任何特殊的实现就可以使用表的排序机制 FXML: 控制器: package br.meuspila.javafx; import br.meuspila.db.Corretora; import java.net.URL; import java.util.ResourceBundle; import javafx.collections.FXCol

我的程序显示一个包含3列的表。单击列的标题时,TableView的内容不会被排序

如果我通过查看列中的排序数据正确理解了这一点,那么我不需要执行任何特殊的实现就可以使用表的排序机制

FXML:

控制器:

package br.meuspila.javafx;

import br.meuspila.db.Corretora;
import java.net.URL;
import java.util.ResourceBundle;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.cell.PropertyValueFactory;

/**
 * FXML Controller class
 */
public class ListarCorretorasController implements Initializable {

    @FXML //  fx:id="tabelaCorretoras"
    private TableView<Corretora> tabelaCorretoras; // Value injected by FXMLLoader
    @FXML //  fx:id="colunaNome"
    private TableColumn<Corretora,String> colunaNome; // Value injected by FXMLLoader
    @FXML //  fx:id="colunaCodigo"
    private TableColumn<Corretora,String> colunaCodigo; // Value injected by FXMLLoader
    @FXML //  fx:id="colunaDescricao"
    private TableColumn<Corretora,String> colunaDescricao; // Value injected by FXMLLoader


    /**
     * Initializes the controller class.
     */
    @Override
    public void initialize(URL url, ResourceBundle rb) {
        colunaNome.setCellValueFactory(new PropertyValueFactory<Corretora,String>("nome"));
        colunaCodigo.setCellValueFactory(new PropertyValueFactory<Corretora,String>("codigo"));
        colunaDescricao.setCellValueFactory(new PropertyValueFactory<Corretora,String>("descricao"));

        ObservableList<Corretora> list = FXCollections.observableArrayList();
        Corretora c1 = new Corretora();
        c1.setNome("RICO");
        c1.setCodigo("1234");
        c1.setDescricao("Testando, 123");
        list.add(c1);
        Corretora c2 = new Corretora();
        c2.setNome("MIRAE");
        c2.setCodigo("4321");
        c2.setDescricao("Mirae 123 testando");
        list.add(c2);

        tabelaCorretoras.setItems(list);
    }    
}
实体/模型:

package br.meuspila.db;

import java.io.Serializable;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;

@Entity
@Table(name = "CORRETORA")
@NamedQueries({
    @NamedQuery(name = "Corretora.findAll", query = "SELECT c FROM Corretora c"),
    @NamedQuery(name = "Corretora.findById", query = "SELECT c FROM Corretora c WHERE c.id = :id"),
    @NamedQuery(name = "Corretora.findByNome", query = "SELECT c FROM Corretora c WHERE c.nome = :nome"),
    @NamedQuery(name = "Corretora.findByCodigo", query = "SELECT c FROM Corretora c WHERE c.codigo = :codigo"),
    @NamedQuery(name = "Corretora.findByDescricao", query = "SELECT c FROM Corretora c WHERE c.descricao = :descricao")})
public class Corretora implements EntityInterface<Corretora>, Serializable {

    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "ID")
    private Long id;

    @Basic(optional = false)
    @Column(name = "NOME")
    private String nome;

    @Column(name = "CODIGO")
    private String codigo = "";

    @Column(name = "DESCRICAO")
    private String descricao = "";

    public Corretora() {
    }

    public Corretora(Long id) {
        this.id = id;
    }

    public Corretora(Long id, String nome) {
        this.id = id;
        this.nome = nome;
    }

    @Override
    public Long getId() {
        return id;
    }

    @Override
    public void setId(Long id) {
        this.id = id;
    }

    public String getNome() {
        return nome;
    }

    public void setNome(String nome) {
        this.nome = nome;
    }

    public String getCodigo() {
        return codigo;
    }

    public void setCodigo(String codigo) {
        this.codigo = codigo;
    }

    public String getDescricao() {
        return descricao;
    }

    public void setDescricao(String descricao) {
        this.descricao = descricao;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Corretora)) {
            return false;
        }
        Corretora other = (Corretora) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "br.meuspila.entity.Corretora[ id=" + id + " ]";
    }

    @Override
    public Corretora clone() {
        Corretora copy = new Corretora();
        copy.setCodigo(this.getCodigo());
        copy.setDescricao(this.getDescricao());
        copy.setId(this.getId());
        copy.setNome(this.getNome());
        return copy;
    }

}

你有没有任何代码可以对物品进行分类?没有。JavaFX应该做到这一点,至少是我在教程中读到的。@JoshM:你认为我需要一些额外的代码吗?该教程说:TableView类提供了在列中对数据进行排序的内置功能。用户可以通过单击列标题更改数据顺序。-@默认情况下,在javafx中列的ceklock排序。。。我想你的java有问题。更新你的java和插件以及软件…我想我可以工作了
package br.meuspila.db;

import java.io.Serializable;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;

@Entity
@Table(name = "CORRETORA")
@NamedQueries({
    @NamedQuery(name = "Corretora.findAll", query = "SELECT c FROM Corretora c"),
    @NamedQuery(name = "Corretora.findById", query = "SELECT c FROM Corretora c WHERE c.id = :id"),
    @NamedQuery(name = "Corretora.findByNome", query = "SELECT c FROM Corretora c WHERE c.nome = :nome"),
    @NamedQuery(name = "Corretora.findByCodigo", query = "SELECT c FROM Corretora c WHERE c.codigo = :codigo"),
    @NamedQuery(name = "Corretora.findByDescricao", query = "SELECT c FROM Corretora c WHERE c.descricao = :descricao")})
public class Corretora implements EntityInterface<Corretora>, Serializable {

    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "ID")
    private Long id;

    @Basic(optional = false)
    @Column(name = "NOME")
    private String nome;

    @Column(name = "CODIGO")
    private String codigo = "";

    @Column(name = "DESCRICAO")
    private String descricao = "";

    public Corretora() {
    }

    public Corretora(Long id) {
        this.id = id;
    }

    public Corretora(Long id, String nome) {
        this.id = id;
        this.nome = nome;
    }

    @Override
    public Long getId() {
        return id;
    }

    @Override
    public void setId(Long id) {
        this.id = id;
    }

    public String getNome() {
        return nome;
    }

    public void setNome(String nome) {
        this.nome = nome;
    }

    public String getCodigo() {
        return codigo;
    }

    public void setCodigo(String codigo) {
        this.codigo = codigo;
    }

    public String getDescricao() {
        return descricao;
    }

    public void setDescricao(String descricao) {
        this.descricao = descricao;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Corretora)) {
            return false;
        }
        Corretora other = (Corretora) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "br.meuspila.entity.Corretora[ id=" + id + " ]";
    }

    @Override
    public Corretora clone() {
        Corretora copy = new Corretora();
        copy.setCodigo(this.getCodigo());
        copy.setDescricao(this.getDescricao());
        copy.setId(this.getId());
        copy.setNome(this.getNome());
        return copy;
    }

}