Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Arrays;
- import java.util.List;
- import javafx.application.Application;
- import javafx.beans.property.SimpleObjectProperty;
- import javafx.beans.value.ObservableValue;
- import javafx.scene.Scene;
- import javafx.scene.SceneAntialiasing;
- import javafx.scene.control.TableColumn;
- import javafx.scene.control.TableView;
- import javafx.stage.Stage;
- import javafx.util.Callback;
- public class BugDemo extends Application {
- @Override
- public void start(Stage primaryStage) {
- List<Double>[] rows = new List[]{
- Arrays.asList(.1, .2, .3, .4, .5),
- Arrays.asList(1, 2, 3, 4, 5),
- Arrays.asList(1, 4, 9, 16, 25),
- Arrays.asList(5, 4, 3, 2, 1),
- Arrays.asList(1, 3, 2, 4, 5)
- };
- // Create the table and add columns
- TableView<List<Double>> table = new TableView<>();
- for (int i = 0; i < 5; i++) {
- table.getColumns().add(makeColumn(i));
- }
- // Add the data
- for (List<Double> row : rows) {
- table.getItems().add(row);
- }
- // This is the problem line! If anti-aliasing is disabled, there is no
- // problem
- Scene scene = new Scene(table, 1200, 800, true, SceneAntialiasing.BALANCED);
- primaryStage.setScene(scene);
- primaryStage.show();
- }
- /**
- * Just a utility method to easily create the columns.
- *
- * @param index
- * @return
- */
- private TableColumn<List<Double>, Double> makeColumn(Integer index) {
- Callback<TableColumn.CellDataFeatures<List<Double>, Double>, ObservableValue<Double>> valuefactory;
- valuefactory = new Callback<TableColumn.CellDataFeatures<List<Double>, Double>, ObservableValue<Double>>() {
- @Override
- public ObservableValue<Double> call(TableColumn.CellDataFeatures<List<Double>, Double> param) {
- return new SimpleObjectProperty<>(param.getValue().get(index));
- }
- };
- TableColumn<List<Double>, Double> result = new TableColumn<>(String.valueOf(index));
- result.setText(String.valueOf((char) ('A' + index))); // A, B, C, ...
- result.setCellValueFactory(valuefactory);
- return result;
- }
- /**
- * @param args the command line arguments
- */
- public static void main(String[] args) {
- launch(args);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement