setMinSize()是否适用于容器,例如GridPane?我发现在我的程序中GridPane忽略了min.手动调整大小时的大小属性.这是FXML代码:
<GridPane fx:id="gp" prefHeight="134.0" prefWidth="238.0" xmlns:fx="http://javafx.com/fxml" fx:controller="javafxapplication12.SampleController">
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
</rowConstraints>
</GridPane>
Run Code Online (Sandbox Code Playgroud)
和控制器类
public class SampleController implements Initializable {
@FXML
private GridPane gp;
@Override
public void initialize(URL url, ResourceBundle rb) {
gp.setMaxWidth(700);
gp.setMinSize(200, 200);
}
Run Code Online (Sandbox Code Playgroud)
这有什么不对?应该有某种"窗口"最大/最小尺寸?
有没有办法从关联的类控制器获取FXML加载文件的Scene对象.
我正在做这样的事情:
@FXML
private AnchorPane anchor;
Scene scene = anchor.getScene();
Run Code Online (Sandbox Code Playgroud)
但我想要一个不引用AnchorPane控件的解决方案.
我的JavaFX Scene Builder v2.0-b14有问题.
不时,该FXML 无法得到打开.即使我删除除了root之外的FXML 中的所有内容.
在任务栏中,它看起来像这样:

如果我重命名文件,我可以正常打开 FXML .

有没有人知道/有这个问题,或者知道SceneBuilder缓存这些东西的位置?
问候,
卡拉施
我遇到了一个我自己无法解决的问题,因为我刚刚开始使用JAVA FX.我得到一个令人讨厌的javafx.fxml.LoadException :,但我完全像一个向导,但我不能让我的Main运行.这是异常输出:
apr 07, 2014 4:06:37 EM application.Main start
ALLVARLIG: null
javafx.fxml.LoadException:
/C:/Users/Jakob/Dropbox/java_kurser/Project%20Timeline/bin/application/LoginGUI.fxml
at javafx.fxml.FXMLLoader.constructLoadException(Unknown Source)
at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
at javafx.fxml.FXMLLoader.load(Unknown Source)
at application.Main.start(Main.java:21)
at com.sun.javafx.application.LauncherImpl$8.run(Unknown Source)
at com.sun.javafx.application.PlatformImpl$7.run(Unknown Source)
at com.sun.javafx.application.PlatformImpl$6$1.run(Unknown Source)
at com.sun.javafx.application.PlatformImpl$6$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl$6.run(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.access$300(Unknown Source)
at com.sun.glass.ui.win.WinApplication$4$1.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: javax.xml.stream.XMLStreamException: ParseError …Run Code Online (Sandbox Code Playgroud) 我创建了一个简单的JavaFX应用程序.

它有两个包,主类JFXTest2.java 在good包中,fxml和它的控制器在JFXTest2包中.
现在的问题是我无法在主类中加载fxml.我试着像这样加载fxml:
Parent root = FXMLLoader.load(getClass().getResource("jfxtest2.Screen.fxml"));
Run Code Online (Sandbox Code Playgroud)
和
Parent root = FXMLLoader.load(getClass().getResource("jfxtest2/Screen.fxml"));
Run Code Online (Sandbox Code Playgroud)
并且
Parent root = FXMLLoader.load(new URL("/jfxtest2/Screen.fxml"));
Run Code Online (Sandbox Code Playgroud)
但是它们都没有工作.所以我应该如何在JFXTest2类中加载来自JFXTest2包的fxml,这是main类或者application class.
我目前在从FXML设置CheckBoxTableCell时遇到问题.我试图将此代码转换为FXML:
tableCol.setCellValueFactory(new PropertyValueFactory<Product, Boolean>("property"));
tableCol.setCellFactory(CheckBoxTableCell.forTableColumn(toStockCol));
Run Code Online (Sandbox Code Playgroud)
其中'property'只是'Product'类的一些属性(来自'boolean'类型).这段代码工作正常.我现在尝试在FXML中设置它,如下所示:
<TableColumn text="Some Col">
<cellValueFactory><PropertyValueFactory property="property" /></cellValueFactory>
<cellFactory><CheckBoxTableCell editable="true" /></cellFactory>
</TableColumn>
Run Code Online (Sandbox Code Playgroud)
这不起作用,我得到以下错误(这是一个FXML LoadExeption):
Caused by: java.lang.IllegalArgumentException: Unable to coerce CheckBoxTableCell@24d62d1e[styleClass=cell indexed-cell table-cell check-box-table-cell]'null' to interface javafx.util.Callback.
at com.sun.javafx.fxml.BeanAdapter.coerce(BeanAdapter.java:495)
at com.sun.javafx.fxml.BeanAdapter.put(BeanAdapter.java:258)
at com.sun.javafx.fxml.BeanAdapter.put(BeanAdapter.java:54)
at javafx.fxml.FXMLLoader$PropertyElement.set(FXMLLoader.java:1409)
at javafx.fxml.FXMLLoader$ValueElement.processEndElement(FXMLLoader.java:786)
at javafx.fxml.FXMLLoader.processEndElement(FXMLLoader.java:2827)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2536)
... 42 more
Run Code Online (Sandbox Code Playgroud)
我无法弄清楚我做错了什么.此外,在我看来,几乎没有关于如何使用FXML在TableView中设置CheckBox的文档.
注意:我想从FXML设置它,因为它似乎是这个的地方.我知道这可以用FXML控制器完成.而且,我只是好奇.
任何帮助是极大的赞赏!
我试图使用JavaFX CSS在按钮中插入图像.虽然,我可以使用"-fx-graphic"标签轻松完成,但我无法找到一种方法来调整我想要的任何大小的图像.
我可以通过以下FXML代码完成此操作,其中我给出了我喜欢的图像宽度30,但我想用纯CSS做到这一点.有没有办法做到这一点?
FXML
<Button text="Press Me">
<graphic>
<ImageView fitWidth="30">
<image>
<Image url="myImage.png"/>
</image>
</ImageView>
</graphic>
</Button>
Run Code Online (Sandbox Code Playgroud)
CSS
#buttonWithImage {
-fx-graphic: url("myImage.png");
}
Run Code Online (Sandbox Code Playgroud) 我想将UI屏幕从更改login.fxml为home.fxml.
我应该改变Stage或Scene?我不确定哪种是最佳做法?另外,我可以在控制器中为处理程序使用lambda表达式吗?
在javafx 2.0中,可以使用FXML方法或使用普通的Java代码来创建布局.关于精心设计的UI集的最佳方法是什么.在我的应用程序中,大约有100个子UI.
谢谢
似乎有点问这个,我认为使用FXML来编写我们的自定义组件显然是正确的方法.
但正如我们从ControlsFX,JFXextras甚至"掌握JavaFX8控件"这本书中看到的那样,不要在自定义控件中使用或提及FXML的使用.
尽管如此,官方文档说要继续这条路线,并通过FXML创建JavaFX控件.
什么是更正确的方式和原因?