Advertisement
Guest User

JavaFX MacOS Bug Demo

a guest
Apr 23rd, 2014
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.40 KB | None | 0 0
  1. import java.util.Arrays;
  2. import java.util.List;
  3. import javafx.application.Application;
  4. import javafx.beans.property.SimpleObjectProperty;
  5. import javafx.beans.value.ObservableValue;
  6. import javafx.scene.Scene;
  7. import javafx.scene.SceneAntialiasing;
  8. import javafx.scene.control.TableColumn;
  9. import javafx.scene.control.TableView;
  10. import javafx.stage.Stage;
  11. import javafx.util.Callback;
  12.  
  13. public class BugDemo extends Application {
  14.  
  15.     @Override
  16.     public void start(Stage primaryStage) {
  17.         List<Double>[] rows = new List[]{
  18.             Arrays.asList(.1, .2, .3, .4, .5),
  19.             Arrays.asList(1, 2, 3, 4, 5),
  20.             Arrays.asList(1, 4, 9, 16, 25),
  21.             Arrays.asList(5, 4, 3, 2, 1),
  22.             Arrays.asList(1, 3, 2, 4, 5)
  23.         };
  24.  
  25.         // Create the table and add columns
  26.         TableView<List<Double>> table = new TableView<>();
  27.         for (int i = 0; i < 5; i++) {
  28.             table.getColumns().add(makeColumn(i));
  29.         }
  30.  
  31.         // Add the data
  32.         for (List<Double> row : rows) {
  33.             table.getItems().add(row);
  34.         }
  35.  
  36.         // This is the problem line! If anti-aliasing is disabled, there is no
  37.         // problem
  38.         Scene scene = new Scene(table, 1200, 800, true, SceneAntialiasing.BALANCED);
  39.  
  40.         primaryStage.setScene(scene);
  41.         primaryStage.show();
  42.     }
  43.  
  44.     /**
  45.      * Just a utility method to easily create the columns.
  46.      *
  47.      * @param index
  48.      * @return
  49.      */
  50.     private TableColumn<List<Double>, Double> makeColumn(Integer index) {
  51.         Callback<TableColumn.CellDataFeatures<List<Double>, Double>, ObservableValue<Double>> valuefactory;
  52.         valuefactory = new Callback<TableColumn.CellDataFeatures<List<Double>, Double>, ObservableValue<Double>>() {
  53.             @Override
  54.             public ObservableValue<Double> call(TableColumn.CellDataFeatures<List<Double>, Double> param) {
  55.                 return new SimpleObjectProperty<>(param.getValue().get(index));
  56.             }
  57.         };
  58.  
  59.         TableColumn<List<Double>, Double> result = new TableColumn<>(String.valueOf(index));
  60.         result.setText(String.valueOf((char) ('A' + index))); // A, B, C, ...
  61.         result.setCellValueFactory(valuefactory);
  62.        
  63.         return result;
  64.     }
  65.  
  66.     /**
  67.      * @param args the command line arguments
  68.      */
  69.     public static void main(String[] args) {
  70.         launch(args);
  71.     }
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement