1 /* 2 * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 package myapp3; 27 28 import java.util.Locale; 29 import java.util.logging.Handler; 30 import java.util.logging.LogRecord; 31 import java.util.logging.Logger; 32 import javafx.animation.KeyFrame; 33 import javafx.animation.Timeline; 34 import javafx.application.Application; 35 import javafx.scene.Scene; 36 import javafx.scene.control.TableColumn; 37 import javafx.scene.control.TableView; 38 import javafx.scene.control.cell.PropertyValueFactory; 39 import javafx.scene.layout.StackPane; 40 import javafx.stage.Stage; 41 import javafx.util.Duration; 42 import myapp3.pkg5.MyData; 43 44 import static myapp3.Constants.*; 45 46 // This logic is copied from AppTableViewExported. 47 48 /** 49 * Modular test application for testing JavaFX beans. 50 * This is launched by ModuleLauncherTest. 51 */ 52 public class AppTableViewQualOpened extends Application { 53 54 /** 55 * @param args the command line arguments 56 */ 57 public static void main(String[] args) { 58 try { 59 Application.launch(args); 60 } catch (Throwable t) { 61 System.err.println("ERROR: caught unexpected exception: " + t); 62 t.printStackTrace(System.err); 63 System.exit(ERROR_UNEXPECTED_EXCEPTION); 64 } 65 } 66 67 private Logger logger; 68 private Handler logHandler; 69 70 private void initLogger() { 71 Locale.setDefault(Locale.US); 72 73 // Initialize Logger 74 logHandler = new Handler() { 75 @Override 76 public void publish(LogRecord record) { 77 final Throwable t = record.getThrown(); 78 // detect any Throwable: 79 if (t != null) { 80 System.err.println("ERROR: unexpected exception was logged: " + record.getMessage()); 81 t.printStackTrace(); 82 System.exit(ERROR_UNEXPECTED_EXCEPTION); 83 } 84 } 85 86 @Override 87 public void flush() { 88 } 89 90 @Override 91 public void close() { 92 } 93 }; 94 95 logger = Logger.getLogger("javafx.scene.control"); 96 logger.addHandler(logHandler); 97 } 98 99 @Override 100 public void start(Stage stage) throws Exception { 101 initLogger(); 102 103 try { 104 StackPane root = new StackPane(); 105 Scene scene = new Scene(root); 106 TableView<MyData> tableView = new TableView<>(); 107 108 // Name column 109 TableColumn<MyData, String> nameCol = new TableColumn<>(); 110 nameCol.setText("Name"); 111 nameCol.setCellValueFactory(new PropertyValueFactory<>("name")); 112 113 // Value column 114 TableColumn<MyData, Integer> valueCol = new TableColumn<>(); 115 valueCol.setText("Value"); 116 valueCol.setCellValueFactory(new PropertyValueFactory<>("value")); 117 118 tableView.getColumns().addAll(nameCol, valueCol); 119 120 tableView.getItems().add(new MyData("Row A", 1)); 121 tableView.getItems().add(new MyData("Row B", 2)); 122 tableView.getItems().add(new MyData("Row C", 3)); 123 124 root.getChildren().add(tableView); 125 126 stage.setScene(scene); 127 stage.show(); 128 129 // Hide the stage after the specified amount of time 130 KeyFrame kf = new KeyFrame(Duration.millis(SHOWTIME), e -> stage.hide()); 131 Timeline timeline = new Timeline(kf); 132 timeline.play(); 133 } catch (Error | Exception ex) { 134 System.err.println("ERROR: caught unexpected exception: " + ex); 135 ex.printStackTrace(System.err); 136 System.exit(ERROR_UNEXPECTED_EXCEPTION); 137 } 138 } 139 140 @Override public void stop() { 141 System.exit(ERROR_NONE); 142 } 143 144 }