- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
您好,我在使用 JavaFX 时遇到了一个奇怪的问题,我正在使用 Scene Builder 为您提供的 Controller 。问题是无论菜单栏上的菜单在单击时什么都不做。这是我的 Controller :
/**
* Sample Skeleton for 'Main.fxml' Controller Class
*/
package com.agronaut022.gui_changer.GUI.Scenes.Main;
import java.io.File;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URISyntaxException;
import java.net.URL;
import java.net.URLDecoder;
import java.security.CodeSource;
import java.util.ResourceBundle;
import org.apache.commons.configuration.ConfigurationException;
import com.agronaut022.gui_changer.GUI.classes.MessageBox;
import com.agronaut022.gui_changer.etc.Config;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.ListView;
import javafx.scene.control.Menu;
import javafx.scene.control.MenuBar;
import javafx.scene.control.ProgressBar;
import javafx.scene.layout.Pane;
import javafx.stage.Stage;
import junit.framework.Test;
public class MainController
`enter code here`{
@FXML
private ResourceBundle resources;
@FXML
private URL location;
@FXML
private ListView<?> ListView;
@FXML
private Button Change_Button;
@FXML
private Menu Help;
@FXML
private Menu about;
@FXML
private MenuBar MenuBar;
@FXML
private Pane pane;
@FXML
private ProgressBar ProgressBar;
@FXML
void initialize() {
assert Help != null : "fx:id=\"Help\" was not injected: check your FXML file 'Main.fxml'.";
assert ListView != null : "fx:id=\"ListView\" was not injected: check your FXML file 'Main.fxml'.";
assert Change_Button != null : "fx:id=\"Change_Button\" was not injected: check your FXML file 'Main.fxml'.";
assert about != null : "fx:id=\"about\" was not injected: check your FXML file 'Main.fxml'.";
assert MenuBar != null : "fx:id=\"MenuBar\" was not injected: check your FXML file 'Main.fxml'.";
assert pane != null : "fx:id=\"pane\" was not injected: check your FXML file 'Main.fxml'.";
assert ProgressBar != null : "fx:id=\"ProgressBar\" was not injected: check your FXML file 'Main.fxml'.";
Help.setOnAction(new EventHandler<ActionEvent>()
{
@Override
public void handle(ActionEvent event)
{
System.out.println("ABout");
Parent root;
try
{
root = FXMLLoader.load(getClass().getClassLoader().getResource("com/agronaut022/gui_changer/GUI/Scenes/About/About.fxml"),
resources);
Stage stage = new Stage();
stage.setTitle("About");
stage.setScene(new Scene(root, 600, 425));
stage.show();
} catch (IOException e)
{
e.printStackTrace();
}
}
});
/* Change_Button.setOnAction(new EventHandler<ActionEvent>()
{
@Override
public void handle(ActionEvent event)
{
Parent root;
try
{
root = FXMLLoader.load(getClass().getClassLoader().getResource("com/agronaut022/gui_changer/GUI/Scenes/About/About.fxml"),
resources);
Stage stage = new Stage();
stage.setTitle("About");
stage.setScene(new Scene(root, 600, 425));
stage.show();
} catch (IOException e)
{
e.printStackTrace();
}
}
}); */
}
}
我的 FXML 文件是这样的
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.*?>
<?import java.lang.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.layout.AnchorPane?>
<Pane fx:id="pane" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="- Infinity" minWidth="-Infinity" prefHeight="600.0" prefWidth="350.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.agronaut022.gui_changer.GUI.Scenes.Main.MainController">
<children>
<MenuBar id="MenuBar" fx:id="MenuBar" layoutY="2.0" prefHeight="25.0" prefWidth="350.0">
<menus>
<Menu mnemonicParsing="false" text="File">
<items>
<MenuItem mnemonicParsing="false" text="Import GUI" />
<MenuItem mnemonicParsing="false" text="Change Starmade Directory" />
<MenuItem mnemonicParsing="false" text="Create Details" />
</items></Menu>
<Menu mnemonicParsing="false" text="Backup" />
<Menu mnemonicParsing="false" text="Settings" />
<Menu fx:id="about" mnemonicParsing="false" text="About" />
<Menu fx:id="Help" mnemonicParsing="false" text="Help" />
</menus>
</MenuBar>
<ListView fx:id="ListView" layoutX="12.0" layoutY="43.0" prefHeight="450.0" prefWidth="326.0" />
<ProgressBar fx:id="ProgressBar" layoutX="12.0" layoutY="499.0" prefHeight="35.0" prefWidth="326.0" progress="0.0" />
<Button id="Change_Button" fx:id="Change_Button" layoutX="12.0" layoutY="540.0" mnemonicParsing="false" prefHeight="48.0" prefWidth="326.0" text="Button" />
</children>
</Pane>
我没有收到任何错误并且程序正确启动,我已经尝试过使用不同的菜单项,但结果相同。
最佳答案
那是因为 Menu
至少没有 Menuitem
不会触发事件。
已经有像你这样的问题了。这是一个解决方案 https://stackoverflow.com/a/19006643/5702956
关于JavaFX 不能使用 onAction,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37512566/
您好,我在使用 JavaFX 时遇到了一个奇怪的问题,我正在使用 Scene Builder 为您提供的 Controller 。问题是无论菜单栏上的菜单在单击时什么都不做。这是我的 Controll
所以我已经有一段时间了,我已经搜索了很多网站和论坛,但是我找不到解决我的问题的方法。 我正在尝试向 .OnAction 添加参数Checkbox 的事件 所以..例如 Dim chk as Check
我有一本工作簿,用作其他人的模板。模板文档已锁定以供编辑,因此最终用户必须使用其项目的具体信息“另存为”。 此模板包括多个工作表以合并所有可能的布局选项。由于与我一起工作的大多数人既没有经验也不熟悉
有没有办法知道 NavLink 何时处于事件状态?像这样的东西?: 最佳答案 您可以使用 NavLink 的 isActive 回调来实现此目的。 isActive 允许您在链接处于事件状态时定义自
嗯,我的问题是我创建了一个 VBA Sub,它接收一个 excel 单元格引用和 2 个文本值以及一个 Variant 作为参数。 Sub CreateButton(oCell, sLabel, sO
这个问题已经有答案了: javafx 8 compatibility issues - FXML static fields or methods (1 个回答) 已关闭 6 年前。 我是 JavaF
我创建了一个新的自定义控件,其中包含标签、文本字段和按钮。如何在 FXML 文件中设置自定义控件的按钮“onAction”方法? 示例代码: 最佳答案 好的,我找到了解决
我的功能区上有几个按钮(目前只有一个拆分按钮和菜单上的几个按钮)。因此,我可以为操作处理程序选择两种不同的设计模式。 模式 #1(常用方法) public void DoStuff(Office.
我设计了一个 Outlook 2010 加载项,我试图在其中触发(或者更确切地说,捕获)单击按钮时触发的事件,如图所示 in this article .我瞄准了正确的 XML(因为在功能区上可以看到
我正在尝试使用以下宏将 vba 代码分配给形状。 使用代码时出现运行时错误 438“对象不支持此属性或方法” 我的工作表编号总是改变,所以我不能将它硬编码到下面的代码中。 这是我正在使用的代码: Su
有没有办法处理 Chrome 打包的 appWindow 事件/非事件状态?类似这样的事件 onActive 或 onFocus。 最佳答案 AppWindow 不提供此功能,但标准 DOM 窗口通过
背景:我有一本记录奥林匹克举重/历史的工作簿。用户可以通过按下调用宏“New_Lift”和“Create_Button”的按钮(添加新电梯)来创建新电梯。这将创建一个包含电梯名称的新工作表,在主工作表
我是 VBA 新手,正在尝试使用 smartArt.Nodes 基于某些单元格数据动态生成组织结构图。我能够毫无问题地生成图表。现在,我希望能够通过单击图表的特定节点来显示它们的更多详细信息。我知道我
我关注了directions here为 Access 应用程序创建自定义功能区。但所有按钮都不起作用!我不断收到一条错误消息,指出 Access 无法找到该函数或宏,即使它是公共(public)的且
假设您有两个工作簿,一个名为“MyWorkbook”,另一个名为“PatchMyWorkbook”。两个工作簿在保存时都打开。 “PatchMyWorkbook”有一个宏,用于添加按钮并将“MyWor
我遇到了一个特殊的问题,尽管在谷歌上搜索和修补了好几个小时,我还是没能解决这个问题。
我正在尝试创建一种方法,以便在按下 Quit MenuItem 时退出应用程序。 我有以下方法: @FXML public void doExit(ActionEvent event) { P
我有一个自定义功能区,菜单中有多个复选框:
我有一个 FXML 编辑器和一个 Controller ,它在 TreeView 中选择时设置域对象。因此,每次在 TreeView 中选择一个新对象时, Controller 都会解除编辑器中所有控
如何将参数传递给在 Excel VBA 中使用 onAction 事件注册的方法? 我的代码是: With ActiveSheet.CheckBoxes.Add(rCell.Left, rCell.T
我是一名优秀的程序员,十分优秀!