在MasonryPane中使用JFoenix Rippler效果

时间:2018-06-08 20:54:53

标签: java javafx jfoenix

这可能是图书馆的问题,或者我无法理解如何利用它。我的目标是以编程方式在masonrypane中添加一些堆栈窗格,并为每个堆栈窗口提供一个JFXrippler,这会在单击时添加涟漪效果。 这是使用JFoenix library和JavaFX

我的代码看起来像这样

爪哇

public class CinemaController implements Initializable {

Gson gson = new GsonBuilder().create();

@FXML
private BorderPane mainPane;

@FXML
private JFXHamburger hamburger;

private JFXMasonryPane masonPane;
@FXML
private StackPane stackPane;

private JFXDrawer drawerMenu;

public static BorderPane root;

@Override
public void initialize(URL url, ResourceBundle rb) {
    root = mainPane;

    masonPane = new JFXMasonryPane();
    masonPane.setMinSize(605, 730);
    setMasonPaneSize(150, 90);      
    stackPane.getChildren().add(masonPane);


    drawerMenu = new JFXDrawer();
    stackPane.getChildren().add(drawerMenu);

    try {
        VBox box = FXMLLoader.load(getClass().getResource("SidePanelContent.fxml"));
        drawerMenu.setSidePane(box);
    } catch (IOException ex) {
        Logger.getLogger(CinemaController.class.getName()).log(Level.SEVERE, null, ex);
    }       

    HamburgerBackArrowBasicTransition burgertask = new HamburgerBackArrowBasicTransition(hamburger);
    burgertask.setRate(-1);
    hamburger.addEventHandler(MouseEvent.MOUSE_PRESSED,(e)->{
        burgertask.setRate(burgertask.getRate()*-1);
        burgertask.play();

        if(drawerMenu.isShown())
        {
            drawerMenu.close();
        }else {
            drawerMenu.open();
        }
    });

    //add all movies        
    for(int i=0; i<10; i++){
        createMovieStackPane(String.valueOf(i));            
    }
}

public void setMasonPaneSize(double w, double h) {
    masonPane.setCellHeight(w);
    masonPane.setCellWidth(h);
}    

public void createMovieStackPane(String movieTitle) {
    StackPane paneChild = new StackPane();
    paneChild.getStyleClass().add("movie-pane");
    StackPane p = new StackPane();
    p.getStyleClass().add("pane");
    Text category = new Text("Foo");     
    // Title in column 3, row 1
    Text chartTitle = new Text("Current Year");

    p.getChildren().add(category);
    p.getChildren().add(chartTitle);
    p.setAlignment(category, Pos.BOTTOM_LEFT);
    p.setAlignment(chartTitle, Pos.TOP_RIGHT); 

    JFXRippler rippler = new JFXRippler(p);
    rippler.setRipplerFill((Paint.valueOf("black")));
    rippler.setMaskType(JFXRippler.RipplerMask.RECT);
    rippler.setPosition(RipplerPos.FRONT);
    paneChild.getChildren().add(p);
    paneChild.setAlignment(p, Pos.CENTER);
    paneChild.getChildren().add(rippler);
    paneChild.resize(120, 80);

    masonPane.getChildren().add(paneChild);        
    }   
}

FXML

<BorderPane fx:id="mainPane" xmlns="http://javafx.com/javafx/8.0.141" xmlns:fx="http://javafx.com/fxml/1" fx:controller="application.CinemaController">
   <top>
      <GridPane minHeight="90.0" minWidth="720.0" BorderPane.alignment="TOP_LEFT">
        <columnConstraints>
          <ColumnConstraints hgrow="SOMETIMES" maxWidth="233.0" minWidth="10.0" prefWidth="10.0" />
            <ColumnConstraints hgrow="SOMETIMES" maxWidth="467.0" minWidth="10.0" prefWidth="467.0" />
          <ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
        </columnConstraints>
        <rowConstraints>
          <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
          <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
          <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
        </rowConstraints>
         <children>
            <JFXHamburger fx:id="hamburger" GridPane.rowIndex="1" GridPane.rowSpan="2" />
         </children>
      </GridPane>
   </top>
   <center>
      <StackPane fx:id="stackPane" prefHeight="200.0" prefWidth="200.0" BorderPane.alignment="CENTER">
         <padding>
            <Insets top="20.0" />
         </padding></StackPane>
   </center>
</BorderPane>

窗格显示正常,一切似乎都正常工作,除了点击时rippler不会触发,我似乎无法将任何鼠标事件分配给堆栈窗格。

我已经尝试过的事情:

  • setPickOnBounds - 无效
  • 删除多余的StackPane - 需要将rippler添加到父节点,并将其添加到 MasonryPane重组,所以他们不是彼此重叠,并且 仍然不会开火

0 个答案:

没有答案