package bug; import java.util.ArrayList; import java.util.LinkedList; import java.util.List; import javafx.application.Application; import javafx.beans.property.SimpleObjectProperty; import javafx.beans.property.SimpleStringProperty; import javafx.beans.property.StringProperty; import javafx.beans.value.ChangeListener; import javafx.beans.value.ObservableValue; import javafx.collections.FXCollections; import javafx.collections.ObservableList; import javafx.event.ActionEvent; import javafx.event.EventHandler; import javafx.geometry.Insets; import javafx.geometry.Pos; import javafx.scene.Node; import javafx.scene.Scene; import javafx.scene.control.CheckMenuItem; import javafx.scene.control.ContextMenu; import javafx.scene.control.Label; import javafx.scene.control.Labeled; import javafx.scene.control.MenuItem; import javafx.scene.control.SelectionMode; import javafx.scene.control.TableColumn; import javafx.scene.control.TableView; import javafx.scene.layout.HBox; import javafx.scene.layout.Pane; import javafx.stage.Stage; import javafx.util.Callback; public class Bug extends Application { public TableView createControl() { ObservableList items = FXCollections.observableArrayList(); for (int i = 0; i < 10; i++) { items.add(new Person("name " + i, "surname " + i)); } TableColumn column1 = new TableColumn("First Name"); column1.setCellValueFactory(new Callback, ObservableValue>() { @Override public ObservableValue call(final TableColumn.CellDataFeatures p) { SimpleObjectProperty text = new SimpleObjectProperty(); text.setValue(new Label(p.getValue().getFirstName())); return text; } }); TableColumn column2 = new TableColumn("Last Name"); column2.setCellValueFactory(new Callback, ObservableValue>() { @Override public ObservableValue call(final TableColumn.CellDataFeatures p) { SimpleObjectProperty text = new SimpleObjectProperty(); text.setValue(new Label(p.getValue().getLastName())); return text; } }); TableView table = new TableView(items); table.getColumns().setAll(column1, column2); table.setPrefHeight(200); table.setFocusTraversable(false); return table; } @Override public void start(Stage stage) throws Exception { TableView tv = createControl(); tv.setPrefWidth(50); tv.setMaxWidth(140); tv.setPrefHeight(80); tv.setMaxHeight(140); HBox box = new HBox(), box1 = new HBox(); box.setStyle("-fx-border-color: darkgray;"); box1.setStyle("-fx-border-color: darkgray;"); box.setPrefSize(200, 70); box1.setPrefSize(200, 70); box.setPadding(new Insets(15, 15, 15, 15)); box.getChildren().add(tv); Pane pane = new Pane(); pane.getChildren().add(box); pane.getChildren().add(box1); Scene scene = new Scene(pane,500,500); stage.setScene(scene); stage.show(); } /** * The main() method is ignored in correctly deployed JavaFX application. * main() serves only as fallback in case the application can not be * launched through deployment artifacts, e.g., in IDEs with limited FX * support. NetBeans ignores main(). * * @param args the command line arguments */ public static void main(String[] args) { launch(args); } public static class Person { Person(String firstName, String lastName) { this.firstName = new SimpleStringProperty(firstName); this.lastName = new SimpleStringProperty(lastName); } public StringProperty firstName; public void setFirstName(String value) { firstName.set(value); } public String getFirstName() { return firstName.get(); } public StringProperty firstNameProperty() { if (firstName == null) { firstName = new SimpleStringProperty(); } return firstName; } public StringProperty lastName; public void setLastName(String value) { lastName.set(value); } public String getLastName() { return lastName.get(); } public StringProperty lastNameProperty() { if (lastName == null) { lastName = new SimpleStringProperty(); } return lastName; } } }