假设我有这样的情况:我有一个TableView(tableAuthors)有两个TableColumns(Id和Name).
这是AuthorProps POJO,用于TableView:
import javafx.beans.property.SimpleIntegerProperty;
import javafx.beans.property.SimpleStringProperty;
public class AuthorProps {
private final SimpleIntegerProperty authorsId;
private final SimpleStringProperty authorsName;
public AuthorProps(int authorsId, String authorsName) {
this.authorsId = new SimpleIntegerProperty(authorsId);
this.authorsName = new SimpleStringProperty( authorsName);
}
public int getAuthorsId() {
return authorsId.get();
}
public SimpleIntegerProperty authorsIdProperty() {
return authorsId;
}
public void setAuthorsId(int authorsId) {
this.authorsId.set(authorsId);
}
public String getAuthorsName() {
return authorsName.get();
}
public SimpleStringProperty authorsNameProperty() {
return authorsName;
}
public void setAuthorsName(String authorsName) …Run Code Online (Sandbox Code Playgroud) 我目前正在评估使用SwingNode将当前的Swing应用程序转换为JavaFX 8是否可行,然后慢慢将所有内容更改为JavaFX组件.我偶然发现了两个问题,这可能是JavaFX 8中的一些问题,但我无法确定.
使JScrollBars不透明似乎不起作用
import java.awt.Color;
import java.awt.GridLayout;
import javafx.application.Application;
import javafx.embed.swing.SwingNode;
import javafx.scene.Scene;
import javafx.scene.control.Menu;
import javafx.scene.control.MenuBar;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
public class Test extends Application {
@Override
public void start(Stage stage) throws Exception {
stage.setMaximized(true);
VBox vbox = new VBox();
MenuBar menuBar = new MenuBar();
menuBar.getMenus().add(new Menu("bla"));
vbox.getChildren().add(menuBar);
StackPane mainPane = new StackPane();
mainPane.setPrefSize(9999, 9999); //Better way to ensure all space used?
vbox.getChildren().add(mainPane);
vbox.setVisible(true);
Scene scene = new Scene(vbox, 9999, 9999); …Run Code Online (Sandbox Code Playgroud)我刚开始使用JavaFX Scene Builder来构建一个小应用程序.
它由一个属于'login.fxml'的控制器类'Login.java'组成,其中FXML文件'registrierung.fxml'通过一个名为'registrationClicked(ActionEvent event)'的方法加载:
public class Login {
@FXML
private void registrationClicked(ActionEvent event){
try{
((Node) (event.getSource())).getScene().getWindow().hide();
FXMLLoader loader = new FXMLLoader(getClass().getResource("/view/fxml/registrierung.fxml"));
Parent root = (Parent) loader.load();
Stage stage = new Stage();
Scene scene = new Scene(root);
stage.setTitle("Registration");
stage.setScene(scene);
stage.setResizable(false);
stage.show();
} catch(IOException e){
e.printStackTrace();
}
}
Run Code Online (Sandbox Code Playgroud)
现在我想通过根节点vboxRoot在控制器类'Registrierung.java'中引用'registrierung.fxml'的阶段:
@FXML
private VBox vboxRoot;
Stage stage = (Stage) vboxRoot.getScene().getWindow();
Run Code Online (Sandbox Code Playgroud)
但是'getScene()'总是会导致NullPointerException.在Scene Builder中调整两个FXML文件的控制器类.
这就是我在'registrierung.fxml'中设置rood节点的方法:
<VBox fx:id="vboxRoot" maxHeight="-Infinity" maxWidth="-Infinity" prefHeight="267.0" prefWidth="355.0" stylesheets="@../css/styles.css" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="businesslogik.Registrierung">
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?
我有TabPane几个Tabs.如果Tab失败中的操作结果,我想将其设置Tab Label为Fill红色或者可能将纹理设置为哈希(对于那些有色盲的人).我想Color稍后将其重置为默认值.
通过阅读这里的一些问题,可以使用样式表静态设置它.
#MyTabPane .tab *.tab-label {
-fx-text-fill: white;
}
Run Code Online (Sandbox Code Playgroud)
如何Tab label动态访问并设置它的颜色/纹理?
tab.setStyle("??");
ELLTZ的补充
一个人怎么可以使用上述内嵌样式来改变Paint双方的Label风格类tab-label和Button(StackPane)也tab-close-button
代码示例需要
我正在玩FilteredList他们已经添加到JDK8中的课程,感觉要快得多 - 似乎让性能更接近GlazedLists.但是,当我使用a FilteredList而不是a 时,表列排序似乎根本不起作用ObservableList.
控制台中没有异常/堆栈跟踪.
以下是我的控制器中的实例成员:
private ObservableList<Film> masterData = FXCollections.observableArrayList();
private FilteredList<Film> filteredData;
Run Code Online (Sandbox Code Playgroud)
我的控制器init:
@FXML
void initialize() {
...
filmTable.setItems(filteredData);
...
}
Run Code Online (Sandbox Code Playgroud)
构造函数:
public FilmBrowserController() {
...
masterData.addAll(filmRepository.findAllSortedByTitle());
filteredData = new FilteredList<>(masterData);
filteredData.setPredicate(film -> true);
}
Run Code Online (Sandbox Code Playgroud)
我一直在通过在更改过滤器TextField时设置新谓词来过滤列表:
filteredData.setPredicate(film ->
film.getTitle().toLowerCase().contains(filterField.getText().toLowerCase()));
Run Code Online (Sandbox Code Playgroud)
我对JavaFX还很绿 - 我错过了一些非常基本的东西,或者这可能是一个bug?我正在使用下载的JDK 8:https://jdk8.java.net/download.html Build b100.
是否不可能有一个可以过滤但同时按列排序的表?
编辑:
修改了我在stackoverflow上找到的另一个javaFX表示例,我添加了这一行(74):
table.setItems(table.getItems().filtered(p -> p.getFirstName().startsWith("a")));
Run Code Online (Sandbox Code Playgroud)
完整来源:
import javafx.application.Application;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
import javafx.beans.value.ObservableValue;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.control.*; …Run Code Online (Sandbox Code Playgroud) 我有一个表格单元工厂负责在JavaFX TableView中创建可编辑单元格.
我正在尝试为tableview实现一些附加功能,以便当用户在可编辑单元格外部单击时进行提交(编辑的文本将被保存,而不会根据默认的tableview行为进行丢弃.)
我添加了一个textField.focusedProperty()事件处理程序,我从文本字段提交文本.但是,当一个单击外部时,当前单元格cancelEdit()被调用并且调用commitEdit(textField.getText());无效.
我已经意识到,一旦cancelEdit()被称为TableCell.isEditing()返回false,所以提交永远不会发生.
如何在用户点击可编辑单元格外部时提交文本?
提交setOnEditCommit()事件处理程序后,将处理验证和数据库逻辑.我没有把它包含在这里,因为它很可能会使事情进一步复杂化.
// EditingCell - for editing capability in a TableCell
public static class EditingCell extends TableCell<Person, String> {
private TextField textField;
public EditingCell() {
}
@Override public void startEdit() {
super.startEdit();
if (textField == null) {
createTextField();
}
setText(null);
setGraphic(textField);
textField.selectAll();
}
@Override public void cancelEdit() {
super.cancelEdit();
setText((String) getItem());
setGraphic(null);
}
@Override public void updateItem(String item, boolean empty) {
super.updateItem(item, empty); …Run Code Online (Sandbox Code Playgroud) 当我运行javafxpackager时,我收到以下警告/信息:
No base JDK. Package will use system JRE.
Run Code Online (Sandbox Code Playgroud)
从部署JavaFX应用程序的文档中不清楚 如何指定替代JDK.它没有选择,我可以看到(也许我是盲目的).它是系统属性吗?
谢谢.
我正在使用javafx v8.0.40开发桌面应用程序.我用inno 5创建了一个exe文件.当我在我的计算机上运行exe文件时,它安装并运行没有任何问题.另一方面,当我尝试在其他计算机上安装并运行它时,在安装结束时会弹出窗口对话框:"错误调用方法",我单击"确定".另一个窗口弹出"无法启动jvm".我搜索了整个互联网,但我找不到这个话题.我希望我能解决这个问题.先感谢您.
我有一个显示最后N个项目的TableView,顶部的新项目,从底部删除项目等...似乎正在发生的事情是CPU负载随着时间的推移而增加,以指示同一台机器上的其他X应用程序变得迟缓.
平台细节:Redhat 6.7,32位,Java 1.8u40
我尝试过的事情
这个问题是较大的应用程序的一部分,但我已将其作为下面的一个较小的例子.这使得其他应用程序在几分钟后变得缓慢,但仅限于Redhat 6u7平台.
public class TableUpdater extends Application {
private int maxItems = 30;
private AtomicBoolean pending = new AtomicBoolean();
public class Thing {
private String foo;
public Thing(String foo) {
this.foo = foo;
} …Run Code Online (Sandbox Code Playgroud) 我正在GUI使用JavaFx,我需要只允许integers选择的滑块.
我知道我可以使用snapToTicks,但在拉动时"knob",它仍然可以代表一个non-integer值.我想摆脱它.它弄乱了与之相关的其他组件.
基本上,我想要类似的东西Swing's JSlider,但有JavaFx.可能吗?我一直在寻找,但我找不到任何东西.
javafx-8 ×10
java ×8
javafx ×5
integer ×1
java-8 ×1
javafx-2 ×1
javafx-css ×1
performance ×1
slider ×1
tabs ×1