我試圖用我的tableview這樣滑動efect: http://jsfiddle.net/43nGr/90/ 我真的不知道該怎麼做。在JavaFx中滑動TableView
這是我的主類的代碼:
import javafx.application.Application;
import javafx.beans.binding.Bindings;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
public class Main extends Application{
Stage window;
TableView <Product> table;
Button showTableButton;
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage primaryStage) throws Exception {
window = primaryStage;
window.setTitle("Liga Pilkarska");
//First Column
TableColumn<Product, String> nameColumn = new TableColumn<>("Name");
nameColumn.setMinWidth(200);
nameColumn.setMaxWidth(200);
nameColumn.setCellValueFactory(new PropertyValueFactory<>("name"));
//Second COlumn
TableColumn<Product, Double> priceColumn = new TableColumn<>("Price");
priceColumn.setMinWidth(100);
priceColumn.setMaxWidth(100);
priceColumn.setCellValueFactory(new PropertyValueFactory<>("price"));
//Third Column
TableColumn<Product, String> quantityColumn = new TableColumn<>("Quantity");
quantityColumn.setMinWidth(200);
quantityColumn.setMaxWidth(200);
quantityColumn.setCellValueFactory(new PropertyValueFactory<>("quantity"));
//Creating a table and adding columns
table = new TableView();
table.setItems(getProduct());
table.getColumns().addAll(nameColumn, priceColumn, quantityColumn);
table.setFixedCellSize(25);
//setting height of table
table.prefHeightProperty().bind(table.fixedCellSizeProperty().multiply(Bindings.size(table.getItems()).add(1.01)));
table.minHeightProperty().bind(table.prefHeightProperty());
table.maxHeightProperty().bind(table.prefHeightProperty());
table.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
showTableButton = new Button("Show Table");
VBox vBox = new VBox();
vBox.getChildren().addAll(showTableButton,table);
//Creating scene
Scene scene = new Scene(vBox, 800,600);
scene.getStylesheets().add("Viper.css");
window.setScene(scene);
window.show();
}
public ObservableList<Product> getProduct(){
ObservableList<Product> products = FXCollections.observableArrayList();
products.add(new Product("Laptop", 2300, 10));
products.add(new Product("Latarka", 50, 19));
products.add(new Product("Suszarka", 89.99, 22));
products.add(new Product("Monitor", 100, 44));
products.add(new Product("Kukurydza", 1.5, 1));
return products;
}
}
,這是我的「產品」類,它是在表的代碼。
public class Product {
public String name;
public double price;
public int quantity;
public Product(){
this.name = "";
this.price = 0;
this.quantity = 0;
}
public Product(String name, double price, int quantity){
this.name = name;
this.price = price;
this.quantity = quantity;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
public int getQuantity() {
return quantity;
}
public void setQuantity(int quantity) {
this.quantity = quantity;
}
}
因此,如果我點擊或懸停在按鈕上,tableView應該開始做滑動efect。 如果有人知道如何做到這一點,那就太好了。