JavaFX:删除分页标签

时间:2017-01-06 15:26:38

标签: java javafx pagination tableview

在互联网上搜索后,我发现了以下用于隐藏分页标签的命令:

-fx-max-page-indicator-count - 设置页面指示符的最大数量。

-fx-arrows-visible - 切换Next和Previous按钮箭头的可见性,默认为true。

-fx-tooltip-visible - 切换页面指示器工具提示的可见性,默认为true。

-fx-page-information-visible - 切换页面信息的可见性,默认为true。

-fx-page-information-alignment - 设置页面信息的对齐方式。

问题是,我该如何使用它们?我无法找到有关此信息的任何信息。我的想法是,当我在ComboBox中更改一个值时,我想隐藏所有分页标签,因为我有三个不同表的三个分页,当我运行程序时,每个分页的标签重叠。

我的控制器代码:

public class AllController {


public void updateSarcina(Observable<Sarcina> observable) 
{
    SarcinaService service = (SarcinaService)observable;
    smodel.setAll(service.getAllSarcinas());
}
public void updatePost(Observable<Post> observable) 
{
    PostService service = (PostService)observable;
    pmodel.setAll(service.getAllPosts());
}
public void updateFisa(Observable<Elementfisa> observable) 
{
    FisaService service = (FisaService)observable;
    fmodel.setAll(service.getAllFisa());
}

public Observer<Sarcina> getSarcinaObserver() 
{
    return new Observer<Sarcina>() 
    {
        @Override
        public void update(Observable<Sarcina> observable) 
        {
            updateSarcina(observable);
        }
    };
}
public Observer<Post> getPostObserver() 
{
    return new Observer<Post>() 
    {
        @Override
        public void update(Observable<Post> observable) 
        {
            updatePost(observable);
        }
    };
}
public Observer<Elementfisa> getFisaObserver() 
{
    return new Observer<Elementfisa>() 
    {
        @Override
        public void update(Observable<Elementfisa> observable) 
        {
            updateFisa(observable);
        }
    };
}

@FXML Pagination paginationS;
@FXML Pagination paginationP;
@FXML Pagination paginationEF;


ObservableList<Sarcina> smodel;
ObservableList<Post> pmodel;
ObservableList<Elementfisa> fmodel;

@FXML private TableView<Post> tableP;
@FXML private TableView<Sarcina> tableS;
@FXML private TableView<Elementfisa> tableEF;

@FXML private TableColumn<Sarcina, String> sFirstColumn;
@FXML private TableColumn<Sarcina, String> sSecondColumn;
@FXML private TableColumn<Post, String> pFirstColumn;
@FXML private TableColumn<Post, String> pSecondColumn;
@FXML private TableColumn<Elementfisa, String> fFirstColumn;
@FXML  private TableColumn<Elementfisa, String> fSecondColumn;

@FXML private ComboBox<String> ComboObject;

@FXML private Label firstLabel;
@FXML private Label secondLabel;
@FXML private Label thirdLabel;

@FXML private TextField firstTextField;
@FXML private TextField secondTextField;
@FXML private TextField thirdTextField;
@FXML private TextField filterTextField;

@FXML private RadioButton radioButtonFirst;
@FXML private RadioButton radioButtonSecond;
@FXML private Button addButton;
@FXML private Button updateButton;
@FXML private Button deleteButton;
@FXML private Button clearFieldsButton;
@FXML private Button raportButton;
@FXML private Pagination pagination ;
SarcinaService sservice;
PostService pservice;
FisaService fservice;

private String currentComboBoxString;

private Boolean isSelectedFC;
private Boolean isSelectedSC;

ToggleGroup toggleRadioGroup = new ToggleGroup();




public AllController() 
{

}

private final static int rowsPerPage = 10;

private Node createPage1(int pageIndex) 
{
    int fromIndex = pageIndex * rowsPerPage;
    int toIndex = Math.min(fromIndex + rowsPerPage, smodel.size());
    tableS.setItems(FXCollections.observableArrayList(smodel.subList(fromIndex, toIndex)));

    paginationS.setPageCount(smodel.size()/7+1);
    return new BorderPane(tableS);
}

private Node createPage2(int pageIndex) 
{
    int fromIndex = pageIndex * rowsPerPage;
    int toIndex = Math.min(fromIndex + rowsPerPage, pmodel.size());
    tableP.setItems(FXCollections.observableArrayList(pmodel.subList(fromIndex, toIndex)));

    paginationP.setPageCount(pmodel.size()/7+1);
    return new BorderPane(tableP);
}

private Node createPage3(int pageIndex) 
{
    int fromIndex = pageIndex * rowsPerPage;
    int toIndex = Math.min(fromIndex + rowsPerPage, fmodel.size());
    tableEF.setItems(FXCollections.observableArrayList(fmodel.subList(fromIndex, toIndex)));

    paginationEF.setPageCount(fmodel.size()/7+1);
    return new BorderPane(tableEF);
}


private int intValidate(String e) 
{
    for(int i = 0; i < e.length(); i++) 
    {
        if(i == 0 && e.charAt(i) == '-') 
        {
            if(e.length() == 1) 
            {
                showErrorMessage("Numar invalid !");
                return -1;
            }
            else continue;
        }
        if(Character.digit(e.charAt(i), 10) < 0) 
        {
            showErrorMessage("Numar invalid !");
            return -1;
        }
    }
    return Integer.parseInt(e);
}
private void fillItemsOnTable(boolean justColumns) 
{

    ObservableList<Sarcina> localModel1 = null;
    ObservableList<Post> localModel2 = null;
    ObservableList<Elementfisa> localModel3 = null;

    if (currentComboBoxString.equals("Sarcina")) 
    {
        tableP.setVisible(false);
        tableEF.setVisible(false);
        tableS.setVisible(true);
        tableS.getColumns().clear();
        tableS.getColumns().add(sFirstColumn);
        tableS.getColumns().add(sSecondColumn);
        localModel1 = this.smodel;
    }
    else if (currentComboBoxString.equals("Post")) 
    {
        tableP.setVisible(true);
        tableEF.setVisible(false);
        tableS.setVisible(false);
        tableP.getColumns().clear();
        tableP.getColumns().add(pFirstColumn);
        tableP.getColumns().add(pSecondColumn);
        localModel2 = this.pmodel;
    }
    else if (currentComboBoxString.equals("Fisa")) 
    {
        tableP.setVisible(false);
        tableEF.setVisible(true);
        tableS.setVisible(false);
        tableEF.getColumns().clear();
        tableEF.getColumns().add(fFirstColumn);
        tableEF.getColumns().add(fSecondColumn);
        localModel3 = this.fmodel;
    }
    if (!justColumns)
    {
        if (localModel1!=null)
        {
            tableS.setItems(localModel1);
            tableP.setVisible(false);
            tableEF.setVisible(false);
            tableS.setVisible(true);
        }
        else
            if (localModel2!=null)
            {
                tableP.setItems(localModel2);
                tableP.setVisible(true);
                tableEF.setVisible(false);
                tableS.setVisible(false);
            }
            else
            {
                tableEF.setItems(localModel3);
                tableP.setVisible(false);
                tableEF.setVisible(true);
                tableS.setVisible(false);
            }
    }
}

@FXML public void handleRaport()
{
    if (isSelectedFC) 
    {
        ObservableList<Sarcina> model = FXCollections.observableArrayList(fservice.filterRapoarte());
        ComboObject.setValue("Sarcina");
        this.fillItemsOnTable(true);
        tableS.setItems(model);
        RaportPDF.addPdf(model);
    }

}

public void setService(SarcinaService sservice, PostService pservice, FisaService fservice) 
{
    this.sservice = sservice;
    this.pservice = pservice;
    this.fservice = fservice;

    this.smodel = FXCollections.observableArrayList(sservice.getAllSarcinas());
    this.pmodel = FXCollections.observableArrayList(pservice.getAllPosts());
    this.fmodel = FXCollections.observableArrayList(fservice.getAllFisa());

    this.fillItemsOnTable(false);
}
@FXML private void onActionComboBox(ActionEvent event) 
{
    String current = ComboObject.getSelectionModel().getSelectedItem();
    if (current.compareTo(currentComboBoxString) != 0) 
    {
        currentComboBoxString = current;
        if (current.equals("Sarcina")) 
        {
            secondLabel.setText("Desc: ");
            radioButtonSecond.setText("By Desc");
            thirdLabel.setVisible(false);
            radioButtonFirst.setVisible(false);
            thirdTextField.setVisible(false);
        }
        else if (current.equals("Post")) 
        {
            secondLabel.setText("Name: ");
            thirdLabel.setText("Type: ");
            radioButtonFirst.setText("By Name");
            radioButtonSecond.setText("By Type");
            thirdLabel.setVisible(true);
            radioButtonFirst.setVisible(true);
            thirdTextField.setVisible(true);
        }
        else if (current.equals("Fisa")) 
        {
            secondLabel.setText("Sarcina ID: ");
            thirdLabel.setText("Post ID: ");
            radioButtonFirst.setText("By Sarcina");
            radioButtonSecond.setText("By Post");
            thirdLabel.setVisible(true);
            radioButtonFirst.setVisible(true);
            thirdTextField.setVisible(true);
        }
        this.fillItemsOnTable(false);
    }
}

@FXML private void initialize() 
{

    TableView<Sarcina> tableS = new TableView<Sarcina>();
    TableView<Post> tableP = new TableView<Post>();
    TableView<Elementfisa> tableEF = new TableView<Elementfisa>();

    ComboObject.getItems().addAll
    (
            "Sarcina",
            "Post",
            "Fisa"
    );
    currentComboBoxString = "Sarcina";
    ComboObject.setValue("Sarcina");

    thirdLabel.setVisible(false);
    radioButtonFirst.setVisible(false);
    thirdTextField.setVisible(false);

    isSelectedFC = true;
    isSelectedSC = false;
    radioButtonFirst.setToggleGroup(toggleRadioGroup);
    radioButtonSecond.setToggleGroup(toggleRadioGroup);
    radioButtonFirst.setSelected(true);

    sFirstColumn.setCellValueFactory(
            new PropertyValueFactory<Sarcina, String>("Id"));

    sFirstColumn.setMinWidth(20);

    sSecondColumn.setCellValueFactory(
            new PropertyValueFactory<Sarcina, String>("desc"));

    sSecondColumn.setMinWidth(160);

    pFirstColumn.setCellValueFactory(
            new PropertyValueFactory<Post, String>("nume"));

    pFirstColumn.setMinWidth(20);

    pSecondColumn.setCellValueFactory(
            new PropertyValueFactory<Post, String>("tip"));

    pSecondColumn.setMinWidth(160);

    fFirstColumn.setCellValueFactory(new Callback<CellDataFeatures<Elementfisa, String>, ObservableValue<String>>()
    {
         public ObservableValue<String> call(CellDataFeatures<Elementfisa, String> p) 
         {
             if (p.getValue() != null && p.getValue().getSarcina() != null) 
             {
                  return new SimpleStringProperty(p.getValue().getSarcina().getDesc());
             } else 
             {
                 return new SimpleStringProperty("Empty");
             }
         }
      });
    fSecondColumn.setCellValueFactory(new Callback<CellDataFeatures<Elementfisa, String>, ObservableValue<String>>() 
    {
         public ObservableValue<String> call(CellDataFeatures<Elementfisa, String> p) 
         {
             if (p.getValue() != null && p.getValue().getPost() != null) 
             {
                  return new SimpleStringProperty(p.getValue().getPost().getNume());
             } else 
             {
                 return new SimpleStringProperty("Empty");
             }
         }
      });

    paginationS.setPageFactory(this::createPage1);
    paginationP.setPageFactory(this::createPage2);
    paginationEF.setPageFactory(this::createPage3);


        tableP.getSelectionModel().selectedItemProperty().addListener((obs, oldSelection, newSelection) -> {
            if (newSelection != null) 
            {
                    firstTextField.setText(((Post) newSelection).getId().toString());
                    secondTextField.setText(((Post) newSelection).getNume());
            }
        });


        tableS.getSelectionModel().selectedItemProperty().addListener((obs, oldSelection, newSelection) -> {
            if (newSelection != null) 
            {
                    firstTextField.setText(((Sarcina) newSelection).getId().toString());
                    secondTextField.setText(((Sarcina) newSelection).getDesc());
            }
        });


        tableEF.getSelectionModel().selectedItemProperty().addListener((obs, oldSelection, newSelection) -> {
            if (newSelection != null) 
            {
                    firstTextField.setText(((Elementfisa) newSelection).getId().toString());
                    secondTextField.setText(((Elementfisa) newSelection).getSarcina().getId().toString());
                    thirdTextField.setText(((Elementfisa) newSelection).getPost().getId().toString());
            }
        });




}

编辑:代码行应该如何找到偶然发现这个问题的人。

    paginationS.setStyle("-fx-arrows-visible: false;");
    paginationS.setStyle("-fx-tooltip-visible: false;");
    paginationS.setStyle("-fx-page-information-visible: false;");

0 个答案:

没有答案