Example usage for javafx.scene.control ScrollPane setMinWidth

List of usage examples for javafx.scene.control ScrollPane setMinWidth

Introduction

In this page you can find the example usage for javafx.scene.control ScrollPane setMinWidth.

Prototype

public final void setMinWidth(double value) 

Source Link

Usage

From source file:fruitproject.FruitProject.java

public void second(final String pfname) {

    final Stage st = new Stage();
    Scene scene = null;/*from ww w . j  a  v a  2 s  .  c  om*/
    final GridPane grid = new GridPane();
    grid.setAlignment(Pos.CENTER);
    grid.setHgap(10);
    grid.setVgap(10);
    grid.setPadding(new Insets(25, 25, 25, 25));
    TableView tv = new TableView();

    final TableColumn<Map, String> firstDataColumn = new TableColumn<>("Name");
    final TableColumn<Map, String> secondDataColumn = new TableColumn<>("Amount");
    final TableColumn<Map, String> thirdDataColumn = new TableColumn<>("Remove");
    firstDataColumn.setMinWidth(130);
    secondDataColumn.setMinWidth(130);
    thirdDataColumn.setMinWidth(130);

    if (!pfname.equals("")) {

        firstDataColumn.setCellValueFactory(new MapValueFactory(Column1MapKey));
        secondDataColumn.setCellValueFactory(new MapValueFactory(Column2MapKey));
        thirdDataColumn.setCellValueFactory(new MapValueFactory(Column3MapKey));

        rows = 0;
        tv = new TableView<>(generateDataInMap(pfname, addPairs));

    }

    tv.getColumns().setAll(firstDataColumn, secondDataColumn, thirdDataColumn);

    // secondDataColumn.setCellFactory(TextFieldTableCell.forTableColumn());

    ScrollPane sp = new ScrollPane();
    sp.setMinWidth(400);
    sp.setHbarPolicy(ScrollBarPolicy.NEVER);
    sp.setContent(tv);
    grid.add(sp, 0, 3);

    final ComboBox comboBox = new ComboBox();
    HBox hb1 = new HBox();
    comboBox.setValue("FILE");
    comboBox.getItems().addAll("Save this file", "Load a new file");
    Button btnOk = new Button();
    btnOk.setText("OK");
    hb1.getChildren().addAll(comboBox, btnOk);
    hb1.setSpacing(10);
    grid.add(hb1, 0, 1);

    Label label1 = new Label("Title:");
    final TextField tfFilename = new TextField();
    tfFilename.setText(getTitle(pfname));
    HBox hb = new HBox();
    hb.getChildren().addAll(label1, tfFilename);
    hb.setSpacing(10);
    grid.add(hb, 0, 2);

    final Stage ps = new Stage();
    final TableView tv1 = tv;
    btnOk.setOnAction(new EventHandler<ActionEvent>() {

        @Override
        public void handle(ActionEvent event) {
            //System.out.println("Hello World!");

            if (comboBox.getValue().equals("Load a new file")) {
                first(ps);
                st.close();
            } else {
                PrintWriter pw = null;
                try {
                    pw = new PrintWriter("abc.json");
                    BufferedWriter bw = new BufferedWriter(new FileWriter(pfname, false));
                    bw.write("{title:\"" + tfFilename.getText() + "\"");
                    bw.write(",fruits:[");
                    for (int i = 0; i < rows; i++) {
                        bw.write("{name:\"" + String.valueOf(firstDataColumn.getCellData(i)) + "\",amount:"
                                + String.valueOf(secondDataColumn.getCellData(i)) + "}");
                        if (i != rows - 1)
                            bw.write(",");
                    }
                    bw.write("]}");

                    bw.close();

                } catch (Exception e) {
                    System.out.println(e.toString());
                }

            }
        }
    });

    Button btn = new Button();
    btn.setText("New Fruit");
    grid.add(btn, 1, 2);

    // TableView tv=new TableView();
    // TableColumn Col1 = new TableColumn("Name");
    // TableColumn Col2 = new TableColumn("Amount");
    // TableColumn Col3 = new TableColumn("Remove");
    // tv.getColumns().addAll(Col1, Col2, Col3);

    //sp.setFitToWidth(true);

    Image img = new Image("file:music.jpg");
    ImageView iv2 = new ImageView();
    iv2.setImage(img);
    iv2.setFitWidth(200);
    iv2.setPreserveRatio(true);
    iv2.setSmooth(true);
    iv2.setCache(true);
    grid.add(iv2, 1, 3);

    btn.setOnAction(new EventHandler<ActionEvent>() {

        @Override
        public void handle(ActionEvent event) {
            //System.out.println("Hello World!");

            System.out.println(comboBox.valueProperty());
            st.close();
            third(pfname);

        }
    });

    scene = new Scene(grid, 700, 450);
    st.setScene(scene);
    st.show();

}