Tag: fxml

Java FX从不同场景改变Label的值

我有两个场景。 第一个场景使用以下代码调用第二个场景。 @FXML private void confirmation(ActionEvent event) throws IOException{ Stage confirmation_stage; Parent confirmation; confirmation_stage=new Stage(); confirmation=FXMLLoader.load(getClass().getResource(“Confirmation.fxml”)); confirmation_stage.setScene(new Scene(confirmation)); confirmation_stage.initOwner(generate_button.getScene().getWindow()); confirmation_stage.show(); } “Confirmation.fxml”中有一个名为“Proceed”的标签。 我需要在此函数中更改该标签的内容并返回结果(true / false)。 帮帮我?

使用事件处理程序加载fxml文件的JavaFX 2.0失败

我正在尝试从子文件夹加载fxml,但它失败了。 我有替换场景内容的行: private Parent replaceSceneContent(String fxml) throws Exception { Parent page = (Parent) FXMLLoader.load(App.class.getResource(“skinFolder/fxml/”+fxml), null, new JavaFXBuilderFactory()); Scene scene = stage.getScene(); if (scene == null) { scene = new Scene(page, 700, 450); scene.getStylesheets().add(App.class.getResource(“skinFolder/css/defaultSkin.css”).toExternalForm()); stage.setScene(scene); } else { stage.getScene().setRoot(page); } stage.sizeToScene(); return page; } 我在下一个方法中使用此函数: private void gotoLogin() { try { replaceSceneContent(“login.fxml”); } catch (Exception ex) […]

NullPointer在setText()上的exception,而所有内容都已正确加载和注释

我从start()方法尝试在带注释的标签上调用setText()时收到以下exception。 我看过一个类似的问题,但之所以对那个人不起作用的原因是因为他的标签没有注释,而我的标签是。 java.lang.NullPointerException at io.github.blubdalegend.openbravery.OpenBravery.applyBuild(OpenBravery.java:67) at io.github.blubdalegend.openbravery.OpenBravery.start(OpenBravery.java:58) at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$162(Unknown Source) at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$175(Unknown Source) at com.sun.javafx.application.PlatformImpl.lambda$null$173(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at com.sun.javafx.application.PlatformImpl.lambda$runLater$174(Unknown Source) at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(Unknown Source) at com.sun.glass.ui.win.WinApplication._runLoop(Native Method) at com.sun.glass.ui.win.WinApplication.lambda$null$148(Unknown Source) at java.lang.Thread.run(Unknown Source) 这是我的主要课程: public class OpenBravery extends Application implements Initializable { @FXML private Button rerollButton; @FXML private Label champL; public static void main(String[] […]

JavaFX从FXML子访问父控制器类

使用JavaFX作为应用程序,我有一个Main.fxml文件,里面有一些fxml子文件。 我想从子控制器访问Main.fxml的MainController类。 我将尝试用一个例子更好地解释: MainFxml: MainController: public class MainController implements Initializable { private String string; public void setString (String string) { this.string = string; } ChildFxml: ChildController: public class ChildController implements Initializable { @FXML HBox child; @FXML Button button; @FXML public void selectButton (ActionEvent event) { // here call MainController.setString(“hello”); } 我尝试在StackOverflow上找到这个解决方案,但是我需要获取已经加载的Main.fxml的Controller引用。 是否有任何方法可以从特定的窗格启动Controller? 就像是: // child.getParent().getController();

在JavaFX中创建行索引列

我有一个JavaFX TableView,我正在使用ObservableList of Tasks填充。 我一直在尝试创建一个显示每行索引的列,它作为表中任务的ID,但我在这里尝试了这个方法,其他来源的类似方法也没有成功。 我的代码供参考,没有表面错误(就Eclipse而言): @FXML private TableColumn taskIndexCol; Callback<TableColumn, TableCell> cb = new Callback<TableColumn, TableCell>(){ @Override public TableCell call(TableColumn col) { TableCell cell = new TableCell() { @Override protected void updateItem(String item, boolean empty) { super.updateItem(item, empty); if (item == null) { setText(“”); } else { setText(getIndex()+””); } } }; return cell; } […]

如何使用现代.fxml和controller.java在javafx 2.x中制作自动完成combobox

如何使用现代.fxml和controller.java在javafx 2.x中制作一个similer autocompletecombobox,因为这个是 http://blog.ngopal.com.np/2011/07/04/autofill-textbox-with-filtermode-in-javafx-2-0-custom-control/ 上面提到的演示是混乱的,很难配置和独立(需要一些jar子)

JavaFX TableView中的属性绑定不起作用

我按照许多链接,在表格视图中找到了一个显示复选框的解决方案。 但是我无法在表视图中更改checkbox的值。 链接我遵循: 如何将CheckBox添加到JavaFX中的TableView 型号类: public class TUser { private SimpleStringProperty name; private SimpleStringProperty address; private SimpleBooleanProperty active; public TUser(String name, String address, boolean active) { this.name = new SimpleStringProperty(name); this.address = new SimpleStringProperty(address); this.active = new SimpleBooleanProperty(active); } public String getName() { return name.get(); } public void setName(String name) { this.name = new SimpleStringProperty(name); […]

在控制器中调用视图方法

我想在控制器中调用视图方法,但我不知道如何:)我寻求的例子,但我没有找到它。 我可以在这段代码中执行此操作吗? 我是否必须重新建造它? 我使用javafx和fxml技术(构建用户界面)。 我的视图文件(它有gotoRegister()和gotoLogin()方法(我想调用它们)) public class FXMLExampleMVC extends Application{ protected Parent root; @Override public void start(Stage stage) throws Exception { gotoLogin(); Scene scene = new Scene(root); stage.setScene(scene); stage.setTitle(“JavaFX Welcome!”); scene.getStylesheets().add(FXMLExampleMVC.class.getResource(“cssforapp.css”).toExternalForm()); stage.show(); } public void gotoRegister() throws IOException{ root = FXMLLoader.load(getClass().getResource(“RegisterFXML.fxml”)); } public void gotoLogin() throws IOException{ root = FXMLLoader.load(getClass().getResource(“Sample.fxml”)); } public static void main(String[] […]

JavaFX Circle和ImageView

我需要使用javaFX2来执行以下操作: 1-)加载图像并使用imageView显示。 [好] 2-)右键单击并选择“添加节点”选项,屏幕上将出现一个黑色圆圈,您可以将圆圈拖动到图像的任何位置。 [好] 3-)使用鼠标滚轮向上或向下缩放imageView,在图像上显示“Zoom Sensation”。 [好] 3.1-) 然而,每次我缩放图像时,我希望我的圆圈遵循比例比例,这意味着它们不能保持在屏幕的相同位置。 [不知道] 我的问题是项目编号3.1,因为我不知道如何在图像中移动我的圆圈,使其在我向上或向下缩放后看起来像是在图像的位置。 我尝试使用setCenterX()和setCenterY()方法,以及转换方法,但我找不到这样做的方法。 加载我的图片的代码: @FXML ImageView bluePrintView; @FXML private void loadBtnAction(ActionEvent event) { FileChooser fileChooser = new FileChooser(); //Show open file dialog File file = fileChooser.showOpenDialog(null); /*Load Image*/ System.out.println(file.getPath()); Image img = new Image(“file:” + file.getPath()); bluePrintView.setImage(img); bluePrintView.setFitHeight(scrollPaneImage.getHeight()); bluePrintView.setFitWidth(scrollPaneImage.getWidth()); bluePrintView.setSmooth(true); bluePrintView.setScaleX(1); bluePrintView.setScaleY(1); event.consume(); } 缩放ImageView的代码: […]

全屏阶段在JavaFX 2.1中无法正常工作?

我加载它的第一个阶段总是作为全屏打开。 stage.setFullScreen(true); stage.setScene(login_scene); 但是,当我更改为另一个FXML时,应用程序保持全屏(没有顶部工具栏..),但实际视图内容在FXML的根AnchorPane的prefWidth / prefHeight上resize(我可以看到我右下角的桌面:| ),我希望它对我的屏幕分辨率是动态的。 谢谢。 @Later编辑: 因此,在我的主要类I的start方法中加载一个Scene(从FXML doc创建)并将其设置为Stage(start方法参数)。 我保存这个阶段供以后使用。 当我按下具有相同阶段的按钮时,我先保存,然后将场景更改为另一个FXML文档 @Screenshots: http://tinypic.com/r/2079nqb/6 – 第一个场景正常工作 – 来自主类的开始覆盖方法的代码 @Override public void start(Stage stage) throws Exception { Parent root = FXMLLoader.load(getClass().getResource(“Sample.fxml”)); stage.setScene(new Scene(root)); stage.setFullScreen(true); stage.show(); currentStage = stage; } http://tinypic.com/r/szfmgz/6 – 重新加载第二个场景后 – 来自示例控制器类的下面的代码 @FXML private void handleButtonAction(ActionEvent event) throws IOException { Parent root = […]