我有这个代码这是非常基本的,它用于关闭TabPane中的所有选项卡.
MenuItem item4 = new MenuItem("Close All Tabs");
item4.setOnAction(new EventHandler<ActionEvent>()
{
@Override
public void handle(ActionEvent e)
{
System.out.println("Close All Tabs");
int ee = tabPane.getTabs().size();
tabPane.getTabs().remove(0, ee);
}
});
Run Code Online (Sandbox Code Playgroud)
我想优化这部分代码:
int ee = tabPane.getTabs().size();
tabPane.getTabs().remove(0, ee);
Run Code Online (Sandbox Code Playgroud)
还有其他明确和优化的解决方案吗?
我有简单的应用程序代码:
webView.getEngine().load("classpath:data/index.html");
Run Code Online (Sandbox Code Playgroud)
自定义URLStreamHandler:
public class Handler extends URLStreamHandler {
private final ClassLoader classLoader;
public Handler() {
this.classLoader = getClass().getClassLoader();
}
public Handler(ClassLoader classLoader) {
this.classLoader = classLoader;
}
@Override
protected URLConnection openConnection(URL u) throws IOException {
URL resourceUrl = classLoader.getResource(u.getPath());
if(resourceUrl == null)
throw new IOException("Resource not found: " + u);
return resourceUrl.openConnection();
}
}
Run Code Online (Sandbox Code Playgroud)
安装人:
URL.setURLStreamHandlerFactory(protocol -> {
if(protocol.equals("classpath")) {
return new Handler();
} else {
return null;
}
});
Run Code Online (Sandbox Code Playgroud)
它加载data/index.html:
<!DOCTYPE html>
<html>
<head>
<title>Test</title>
</head>
<body>
<div>Hello, …Run Code Online (Sandbox Code Playgroud) 当用户选择/取消选择CheckBox时,我想更改JavaFX TableView的行高。我能找到的唯一方法是通过CSS,所以我尝试了:
if (someCheckBox.isSelected())
tableView.setStyle(".table-row-cell {-fx-cell-size: 60px;}");
else
tableView.setStyle(".table-row-cell {-fx-cell-size: 20px;}");
Run Code Online (Sandbox Code Playgroud)
但这是行不通的。任何建议,将不胜感激。
我有以下类ProtokollEvent
public class ProtokollEvent extends Event {
//variable holds all devices in given protokoll
private ObservableList<Device> devicesList;
//variable holds SaveResult
private SaveResult result;
//final ProtokollEvents
public static final EventType<ProtokollEvent> PROTOKOLL_SAVE = new EventType(ANY, "PROTOKOLL_SAVE");
public static final EventType<ProtokollEvent> PROTOKOLL_SAVE_DONE = new EventType(ANY, "PROTOKOLL_SAVE_DONE");
public static final EventType<ProtokollEvent> PROTOKOLL_UPDATED = new EventType(ANY, "PROTOKOLL_UPDATED");
public static final EventType<ProtokollEvent> PROTOKOLL_DELETED = new EventType(ANY, "PROTOKOLL_DELETED");
public ProtokollEvent() {
this(PROTOKOLL_SAVE);
}
public ProtokollEvent(EventType<? extends Event> arg0) {
super(arg0);
}
public ProtokollEvent(Object arg0, EventTarget arg1, EventType<? …Run Code Online (Sandbox Code Playgroud) 我有一个非常简单的GridPane示例.
GridPane playerGrid = new GridPane();
Text title = new Text("Top Scorers in English Premier League");
title.setFont(Font.font("Arial", FontWeight.BOLD, 20));
playerGrid.add(title, 0,0,4,1);
Run Code Online (Sandbox Code Playgroud)
如何用鼠标选择文本并在程序运行时复制它?
我想点击一个功能按钮.
我知道这在我们使用的java应用程序中是可行的
jButton1.doClick();
Run Code Online (Sandbox Code Playgroud)
在javafx中有没有做同样的工作
请帮我
谢谢.
实际上我在使用TableView的JavaFX应用程序中遇到了问题.我不是没有原因,但是,当我在运行时将数据加载到TableView时,JavaFX不会渲染某些行,如下图所示:

但是,当我调整列的大小时,会显示以下数据:

Bellow遵循使用的源代码:
public void loadData()
{
// Define the TableView columns using Reflection defined by ResultSetMetadata
ArrayList<TableColumn> gridColumns = defineGridColumns(data.get(0));
this.tableView.getColumns().clear();
this.tableView.getColumns().addAll(gridColumns);
// Load data to TableView
this.tableView.setItems(FXCollections.observableArrayList(data));
}
private void defineGridColumns(Object singleData)
{
ArrayList<TableColumn> gridColumns = new ArrayList<>();
Field[] fields = singleData.getClass().getFields();
for (int i = 0; i < fields.length; i++)
{
TableColumn column = createTableColumn(fields[i].getName());
this.gridColumns.add(column);
}
return gridColumns;
}
private TableColumn createTableColumn(String columnName)
{
TableColumn column = new TableColumn(columnName);
column.setCellValueFactory(new PropertyValueFactory(columnName));
column.setPrefWidth(columnName.length() * 20);
HBox box …Run Code Online (Sandbox Code Playgroud) 我试图插入我的数据库的一个表,但这个过程需要几分钟.
我希望在我的应用程序尝试插入时有一个不确定的进度条.为了有进度条,我想使用JavaFX,但我不知道如何实现它,直到插入数据库进程结束才显示它.
以下是Pro JavaFx 8的示例:
package projavafx.reversi.examples;
import javafx.application.Application;
import javafx.beans.binding.Bindings;
import javafx.geometry.Pos;
import javafx.scene.Node;
import javafx.scene.Scene;
import javafx.scene.effect.DropShadow;
import javafx.scene.effect.InnerShadow;
import javafx.scene.layout.*;
import javafx.scene.paint.Color;
import javafx.scene.paint.CycleMethod;
import javafx.scene.paint.RadialGradient;
import javafx.scene.paint.Stop;
import javafx.scene.shape.Ellipse;
import javafx.scene.text.Font;
import javafx.scene.text.FontWeight;
import javafx.scene.text.Text;
import javafx.stage.Stage;
import projavafx.reversi.model.Owner;
import projavafx.reversi.model.ReversiModel;
/**
* @author Stephen Chin <steveonjava@gmail.com>
*/
public class BorderLayoutExample extends Application {
TilePane scoreTiles;
TilePane titleTiles;
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage primaryStage) {
BorderPane borderPane = new BorderPane();
borderPane.setTop(createTitle()); …Run Code Online (Sandbox Code Playgroud) 我面临着一个奇怪的问题.我有一个可编辑的ComboBox和一些项目.运行我的代码后如果我在ComboBox中键入内容并调用getValue()函数,那么它会给我null值.
这是我的代码(thenewboston):包应用程序;
import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.ComboBox;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
public class Main extends Application {
Stage window;
Scene scene;
Button button;
ComboBox<String> comboBox;
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage primaryStage) throws Exception {
window = primaryStage;
window.setTitle("ComboBox Demo");
button = new Button("Submit");
comboBox = new ComboBox<>();
comboBox.getItems().addAll(
"Good Will Hunting",
"St. Vincent",
"Blackhat"
);
comboBox.setPromptText("What is your favorite movie?");
comboBox.setEditable(true);
button.setOnAction(e -> printMovie()); …Run Code Online (Sandbox Code Playgroud)