我开始学习JavaFX 2.0并安装了Netbeans 7.1,java 7.02 SDK(包含JavaFX 2).一切似乎都有效,示例项目编译并运行良好.
我的问题是:代码完整不适用于FXML文件.我按ctrl + space,每次都显示"无建议".标签和属性也是如此.
有谁知道可能是什么问题?
我想在JavaFX中更改Menu控件的文本颜色.目前,整个菜单栏的背景颜色设置为白色,显示菜单 -s 的默认文本颜色也是白色,所以我看不到实际控件,因此我想设置菜单的文本颜色("文件" ")黑色.我怎么做?
这是FXML部分:
<?import java.lang.*?>
<?import java.net.*?>
<?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>
<MenuBar id="modBar" layoutX="176.0" layoutY="122.0" styleClass="modBar">
<menus>
<Menu id="modItem" mnemonicParsing="false" styleClass="modItem" text="File" />
</menus>
<stylesheets>
<URL value="test.css" />
</stylesheets>
</MenuBar>
</children>
</AnchorPane>
Run Code Online (Sandbox Code Playgroud)
这是CSS部分:
.modBar
{
-fx-background-color: white;
}
.modItem
{
-fx-color: black;
}
Run Code Online (Sandbox Code Playgroud)
这不起作用("文件"仍然是白色的).我究竟做错了什么?另外,我似乎无法将任何 CSS应用于.modItem - 它可以在 …
我使用JavaFX Scene Builder将一个ChoiceBox放在一个fxml中.
FXML有一个分配给它的控制器.
我的问题是:如果我想了解更改的值,我需要注册哪个事件?
onInputMethodTextChanged="#languageSelectionModified"
Run Code Online (Sandbox Code Playgroud)
这不适用于以下代码
public void languageSelectionModified(Event event) {
ChoiceBox<String> box = (ChoiceBox<String>) event.getSource();
System.out.println(box.getValue());
}
Run Code Online (Sandbox Code Playgroud)
这仅适用于初始点击(即打开列表,而不是选择项目时):
onMouseClicked="#languageSelectionModified"
Run Code Online (Sandbox Code Playgroud)
虽然鼠标事件永远不会是一个很好的选择,因为触摸或键盘是输入法的情况,它仍然证明可以到达System.out.
我绝对不知道这些东西在哪里被记录(在默认的Java-API中它们不是)
我想找到装有一个场景中的垂直框节点FXMLoader感谢Node#lookup(),但我得到以下异常:
java.lang.ClassCastException: com.sun.javafx.scene.control.skin.SplitPaneSkin$Content cannot be cast to javafx.scene.layout.VBox
代码 :
public class Main extends Application {
public static void main(String[] args) {
Application.launch(Main.class, (java.lang.String[]) null);
}
@Override
public void start(Stage stage) throws Exception {
AnchorPane page = (AnchorPane) FXMLLoader.load(Main.class.getResource("test.fxml"));
Scene scene = new Scene(page);
stage.setScene(scene);
stage.show();
VBox myvbox = (VBox) page.lookup("#myvbox");
myvbox.getChildren().add(new Button("Hello world !!!"));
}
}
Run Code Online (Sandbox Code Playgroud)
fxml文件:
<AnchorPane id="AnchorPane" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns:fx="http://javafx.com/fxml" >
<children>
<SplitPane dividerPositions="0.5" focusTraversable="true" prefHeight="400.0" prefWidth="600.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" …Run Code Online (Sandbox Code Playgroud) 我改进了我以前的TextField验证实现,这次使用绑定进行实时验证的真正自定义控件.它可以与FXML一起使用而无需更多的Java代码.
import javafx.beans.binding.BooleanBinding;
import javafx.beans.property.BooleanProperty;
import javafx.beans.property.IntegerProperty;
import javafx.beans.property.ReadOnlyBooleanProperty;
import javafx.beans.property.ReadOnlyIntegerProperty;
import javafx.beans.property.ReadOnlyStringProperty;
import javafx.beans.property.SimpleBooleanProperty;
import javafx.beans.property.SimpleIntegerProperty;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.scene.control.TextField;
import javafx.scene.effect.BlurType;
import javafx.scene.effect.DropShadow;
import javafx.scene.effect.Effect;
import javafx.scene.paint.Color;
/**
* <p>
* TextField with regex-based real-time input validation.
* JavaFX 2 and FXML compatible. </p>
* <p>
* FXML code example:<div>
* {@code <ValidatedTextField fx:id="validatedTextField" minLength="1" maxLength="1" mask="^[0-9]*$" />}
* </div>
* </p>
*
* @author 82300009
*/
public final class ValidatedTextField extends …Run Code Online (Sandbox Code Playgroud) 我想关闭然后重新启动已经运行的应用程序(自动),通过单击按钮或类似的东西,我想这样做是为了用其他语言重新启动应用程序,我是一般来说是JavaFx和Java的新手,请问您能为我解决这个问题吗?
我知道由于jewelsea,可以在TableView中创建一个充满按钮的列.
但我想知道是否可以直接在FXML中定义它.
例如,与其他类型的一个做:
班级人员:
private final SimpleStringProperty birthDate = new SimpleStringProperty("");
Run Code Online (Sandbox Code Playgroud)
然后在FXML中:
<TableView fx:id="table" layoutY="50.0" prefHeight="350.0" prefWidth="600.0">
<columns>
<TableColumn prefWidth="79.5" text="date of birth">
<cellValueFactory>
<PropertyValueFactory property="birthDate" />
</cellValueFactory>
</TableColumn>
</columns>
</TableView>
Run Code Online (Sandbox Code Playgroud)
并且可以添加以下元素:
@FXML private TableView<Person> table;
//...
table.getItems().add("12/02/1452");
Run Code Online (Sandbox Code Playgroud)
如何用Buttons实现同样的目标?
I was working on a stage when I noticed I practically had the exact same thing three times. Rather than that (since I hate that), I decided to take what I had those 3 times and turn it into a custom component.
Now I know I can add it in code but I can't predict the layout behavior (two of these will be going into tabs directly, and the third will be going into a grid pane).
I tried importing …
我正在尝试在fxml文件中创建一个fileChooser.我的代码看起来像这样:
<HBox alignment="CENTER">
<Label text="Tower 1 Image" />
<TextField fx:id="tower1ImageField" />
<FileChooser fx:id ="tower1FileChooser" />
</HBox>
Run Code Online (Sandbox Code Playgroud)
控制器读起来像这样:
public class HudBuilderController{
@FXML TextField tower1ImageField;
@FXML FileChooser tower1FileChooser;
File towerFile;
@FXML TextField tower2ImageField;
@FXML FileChooser tower2FileChooser;
}
Run Code Online (Sandbox Code Playgroud)
但是,我收到一个我不明白的错误:
Caused by: java.lang.IllegalArgumentException: Unable to coerce javafx.stage.FileChooser@5e85f35 to class javafx.scene.Node.
at com.sun.javafx.fxml.BeanAdapter.coerce(Unknown Source)
at javafx.fxml.FXMLLoader$Element.add(Unknown Source)
at javafx.fxml.FXMLLoader$ValueElement.processEndElement(Unknown Source)
at javafx.fxml.FXMLLoader.processEndElement(Unknown Source)
... 26 more
Run Code Online (Sandbox Code Playgroud)
我已经尝试在控制器中实例化FileChooser,但我想我需要在fxml文件中添加更多内容.有帮助吗?谢谢!
是否可以在FXML中设置ColorPicker的默认颜色,还是必须在FXML控制器的initialize方法中设置颜色?
fxml ×10
javafx-2 ×7
java ×6
javafx ×5
autocomplete ×1
css ×1
eclipse ×1
javafx-8 ×1
menu ×1
netbeans-7 ×1
scenebuilder ×1
textfield ×1
validation ×1