是否可以将网格窗格扩展到最大宽度和高度?
我有以下内容:
<fx:root type="javafx.scene.layout.AnchorPane" xmlns:fx="http://javafx.com/fxml"
stylesheets="view/Style.css">
<children>
<GridPane xmlns:fx="http://javafx.com/fxml"
AnchorPane.topAnchor="0.0" AnchorPane.bottomAnchor="128.0"
AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0"
hgap="10" vgap="10">
<!--anything-->
</GridPane>
</children>
</fx:root>
Run Code Online (Sandbox Code Playgroud)
并且我想将网格窗格扩展到由锚定窗格确定的限制(因此整个屏幕除了下部)
我正在尝试使用JavaFX和SceneBuilder 1.1进行自定义控件.
我有这个代码:
FXML
<?import libreria.javaFX.componentes.componenteTextField.*?>
<AnchorPane id="AnchorPane" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns:fx="http://javafx.com/fxml">
<children>
<CustomComponent fx:id="pastaTxt" layoutX="69.0" layoutY="87.0" prefWidth="200.0" />
</children>
</AnchorPane>
Run Code Online (Sandbox Code Playgroud)
CustomComponent.java
package libreria.javaFX.componentes.componenteTextField;
import javafx.scene.control.TextField;
public class CustomComponent extends TextField {
public CustomComponent() {
super();
// TODO Auto-generated constructor stub
}
public CustomComponent(String arg0) {
super(arg0);
// TODO Auto-generated constructor stub
}
Run Code Online (Sandbox Code Playgroud)
}
当我尝试从SceneBuilder打开它时它会告诉我:
缺少的类型有:[CustomComponent]
它让我有机会指定Classpath(它也不能解决问题).
我尝试将类放在import语句中,如下所示:
<?import libreria.javaFX.componentes.componenteTextField.CustomComponent?>
Run Code Online (Sandbox Code Playgroud)
但它给了一个ClassNotFoundException.
关于为什么会发生这种情况的任何想法?
更多信息
我只使用这些类完成了一个新项目:

代码如下:
CustomControl.fxml
<?xml version="1.0" encoding="UTF-8"?>
<?import custom.CustomControl?>
<?import java.lang.*?>
<?import java.util.*?> …Run Code Online (Sandbox Code Playgroud) 我正在为一个节点添加一个样式类,如果它被选中,如果我选择其他项目则将其删除.即使我删除样式类,样式也不会刷新,所以它不会回到正常状态:
admin_category_label.getStyleClass().remove(admin_category_label.getStyleClass().indexOf("selected"));
admin_category_label.getStyleClass().add("clear");
Run Code Online (Sandbox Code Playgroud)
但风格将与所选的课程保持一致
我正在使用JavaFX Scene Builder构建JavaFX应用程序.界面是在Scene Builder中创建的,并创建了一个FXML文件(main.fxml).
要在我的应用程序中使用该接口,我必须使用FXMLLoader加载FXML文件,但是有一个问题因为load()方法返回一个Object,并且要构建一个Scene我需要一个Parent类的实例.
下面是我的MainClass的一部分.编译器发出错误,因为页面不是Parent类型:
Object page = FXMLLoader.load(MainWindowController.class.getResource("main.fxml"));
Scene scene = new Scene(page);
primaryStage.setScene(scene);
primaryStage.show();
Run Code Online (Sandbox Code Playgroud)
如何使编译和运行正确?
这是FXML文件(main.fxml):
<?xml version="1.0" encoding="UTF-8"?>
<?import java.lang.*?>
<?import java.util.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.paint.*?>
<AnchorPane id="AnchorPane" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns:fx="http://javafx.com/fxml">
<children>
<VBox prefHeight="400.0" prefWidth="600.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<children>
<MenuBar minHeight="21.0" prefHeight="21.0" prefWidth="600.0">
<menus>
<Menu mnemonicParsing="false" text="File">
<items>
<MenuItem mnemonicParsing="false" text="Close" />
</items>
</Menu>
<Menu mnemonicParsing="false" text="Edit">
<items>
<MenuItem mnemonicParsing="false" text="Delete" /> …Run Code Online (Sandbox Code Playgroud) 我想为网站开发一个客户端应用程序.
我希望应用程序在最小化时驻留在系统托盘中.
我不知道如何完成这项任务.
他们是这种类型的操作的任何例子.
我有一个BorderPane(与MainController相关联),BorderPane的FXML用于在BorderPane <fx:include>的底部区域包含一个Label(带有控制器StatusBarController).不幸的是,StatusBarController没有注入到MainController类实例中,我无法理解为什么.
main.fxml:包含状态栏的BorderPane
<fx:root type="javafx.scene.layout.BorderPane" fx:id="borderPane" xmlns:fx="http://javafx.com/fxml" fx:controller="com.example.controllers.MainController">
<bottom>
<fx:include source="statusbar.fxml" />
</bottom>
</fx:root>
Run Code Online (Sandbox Code Playgroud)
statusbar.fxml:Label及其关联的控制器
<Label fx:id="statusbar" text="A label simulating a status bar" xmlns:fx="http://javafx.com/fxml" fx:controller="com.example.controllers.StatusBarController" />
Run Code Online (Sandbox Code Playgroud)
带有StatusBarController字段的MainController:
public class MainController
{
@FXML
private StatusBarController statusbarController; // PROBLEM HERE: I would expect the StatusBarController to be injected but this does not happen!
// Implementing Initializable Interface no longer required on JavaFX 2.2 according to
// http://docs.oracle.com/javafx/2/fxml_get_started/whats_new2.htm
// (I also tested this, the initialize() method is being called)
@SuppressWarnings("unused") // only …Run Code Online (Sandbox Code Playgroud) 我一直在尝试使用自定义实现FXMLLoader的setControllerFactory方法Callback<P,R>.
ORACLE文档说明如下:
实现可能返回null值以指示它不能或不能创建给定类型的控制器; 在这种情况下,加载器将使用默认控制器构造机制.
我想要实现的结果是我可以使用依赖注入框架来创建任何需要参数的控制器,但我会让FXMLLoader任何不需要参数的控制器加载.
所以,如果我有以下简单的FXML文件,它使用ViewController不接受参数的类...
<StackPane fx:id="pane"
xmlns:fx="http://javafx.com/fxml"
fx:controller="my.package.ViewController">
</StackPane>
Run Code Online (Sandbox Code Playgroud)
并且我使用以下简单的控制器工厂实现来发信号通知FXMLLoader我希望它在这种情况下管理控制器的构造...
loader.setControllerFactory(new Callback<Class<?>, Object>(){
@Override
public Object Call(Class<?> type) {
return null; // Let the FXMLLoader handle construction...
}
});
Run Code Online (Sandbox Code Playgroud)
在调用load()方法之后,我的ViewController类中的Initialise方法永远不会被调用(我已用断点验证了这一点).
如果我更改我的控制器工厂实现以返回ViewController该类的实例,那么一切都按预期工作.
任何人都可以帮我解决我的困惑吗?我是否Callback错误地使用了界面或者ORACLE文档不正确?
我试图基于menuItem单击更改javafx阶段中的场景.这是我的sample.fxml:
<?xml version="1.0" encoding="UTF-8"?>
<?import java.lang.*?>
<?import java.net.*?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.*?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.image.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.layout.GridPane?>
<AnchorPane prefHeight="-1.0" prefWidth="560.0" styleClass="background" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/2.2" fx:controller="sample.Controller">
<children>
<MenuBar layoutY="0.0" maxWidth="1.7976931348623157E308" prefWidth="300.0" useSystemMenuBar="false" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="2.0">
<menus>
<Menu id="manageAccountsMenu" mnemonicParsing="false" onAction="#onManageAccountsMenuActionPerformed" text="Accounts" fx:id="manageAccountsMenu">
<items>
<MenuItem mnemonicParsing="false" onAction="#onTweetsMenuActionPerformed" text="Manage" fx:id="manageAccountsSubmenuItem" />
</items>
</Menu>
<Menu mnemonicParsing="false" onAction="#onTweetsMenuActionPerformed" text="Tweets" fx:id="tweetsMenuItem" />
<Menu mnemonicParsing="false" text="Retweets" />
</menus>
</MenuBar>
<VBox id="VBox" alignment="CENTER" layoutY="24.0" spacing="5.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0">
<children>
<ScrollPane id="ScrollPane" fitToHeight="true" fitToWidth="true" prefViewportHeight="400.0" prefViewportWidth="300.0">
<content> …Run Code Online (Sandbox Code Playgroud) 我是JavaFX的新手,我正在尝试用它做一个项目.在一些教程中,他们提到了FXML.两者有什么区别?
我正在使用NetBeans IDE开发我的项目,并在使用FXML时听说过使用Scene Builder.什么是Scene Builder?我应该使用JavaFX,FXML和Scene Builder来顺利开发我的项目吗?
请用简单的语言回答上述问题.如果可能的话,请给我一些关于如何使用JavaFX的好教程.
如果为视图使用FXML,如何正确扩展自定义JavaFX组件以添加或修改其GUI组件?
作为示例场景,假设我使用以下方法创建自定义JavaFX组件:
SpecializedButton.java(控制器)
package test;
import java.io.IOException;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.layout.HBox;
public class SpecializedButton extends HBox
{
@FXML private Button button;
@FXML private Label label;
public SpecializedButton()
{
FXMLLoader loader = new FXMLLoader( getClass().getResource( "SpecializedButton.fxml" ) );
loader.setRoot( this );
loader.setController( this );
try {
loader.load();
} catch ( IOException e ) {
throw new RuntimeException( e );
}
}
// specialized methods for this specialized button
// ...
public void doSomething() {
button.setText( …Run Code Online (Sandbox Code Playgroud) fxml ×10
javafx-2 ×7
java ×5
javafx ×5
scenebuilder ×3
controller ×1
css ×1
inheritance ×1
styles ×1
system-tray ×1