好的,我通过一些 CSS 修改来更改 DatePicker 样式;但是,所选日期不再显示。这是我的新 DatePicker
这是我的 CSS,使这个时髦的事情成为可能
.date-picker-popup > .month-year-pane {
-fx-padding: 0.588883em 0.5em 0.666667em 0.5em;
-fx-background-color: -fx-main-back;
-fx-background-insets: 0 0 0 0, 0 0 1 0;
}
.date-cell {
-fx-background-color: -fx-main-back;
-fx-font-family: "Andalus";
-fx-font-size: 16.0;
-fx-text-fill: -fx-type;
}
.date-cell:hover {
-fx-background-color: -fx-type;
-fx-font-family: "Andalus";
-fx-font-size: 16.0;
-fx-text-fill: -fx-main-back;
}
Run Code Online (Sandbox Code Playgroud)
不确定所选日期的 CSS 是什么。我尝试过各种各样的东西,比如
.date-cell:selected {
-fx-background-color: -fx-type;
-fx-font-family: "Andalus";
-fx-font-size: 16.0;
-fx-text-fill: -fx-main-back;
}
.date-cell:focused {
-fx-background-color: -fx-type;
-fx-font-family: "Andalus";
-fx-font-size: 16.0;
-fx-text-fill: -fx-main-back;
}
.date-cell-selected {
-fx-background-color: -fx-type; …Run Code Online (Sandbox Code Playgroud) 我在 JavaFX 中使用 fxml,并且想要一个列表主/详细视图。左侧的固定大小的列表,以及宽度随着窗口大小而增长的 TextArea 的细节。
这是我的 fxml:
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.ListView?>
<?import javafx.scene.control.Menu?>
<?import javafx.scene.control.MenuBar?>
<?import javafx.scene.control.MenuItem?>
<?import javafx.scene.control.TextArea?>
<?import javafx.scene.layout.BorderPane?>
<?import javafx.scene.layout.HBox?>
<BorderPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="800.0" prefWidth="1280.0" xmlns="http://javafx.com/javafx/8.0.111" xmlns:fx="http://javafx.com/fxml/1">
<top>
<MenuBar prefWidth="671.0" BorderPane.alignment="CENTER">
<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" />
</items>
</Menu>
<Menu mnemonicParsing="false" text="Help">
<items>
<MenuItem mnemonicParsing="false" text="About" />
</items>
</Menu>
</menus>
</MenuBar>
</top>
<center>
<HBox BorderPane.alignment="CENTER">
<children>
<ListView prefHeight="754.0" prefWidth="236.0" /> …Run Code Online (Sandbox Code Playgroud) 我想在操作 TableColumn 中添加两个按钮,我已经阅读了How to add button in JavaFX table view和Add a button to a cells in a TableView (JAVAFX)但它们都使用一个按钮setGraphic,所以当我尝试使用 :
actionFld.setCellFactory(param -> new TableCell<Patient, Patient>() {
private final JFXButton editButton = new JFXButton("edit");
private final JFXButton deleteButton = new JFXButton("delete");
@Override
protected void updateItem(Patient patient, boolean empty) {
super.updateItem(patient, empty);
if (patient == null) {
setGraphic(null);
return;
}
deleteButton.setOnAction(event -> {
Patient getPatient = getTableView().getItems().get(getIndex());
System.out.println(getPatient.getNom() + " " + getPatient.getPrenom());
});
editButton.setOnAction(event -> …Run Code Online (Sandbox Code Playgroud) 问题出在 ListView 边框处的灰线中。我已经将边框颜色设置为透明,但它不起作用。如果我将边框颜色设置为黑色,它只会绘制在灰线的顶部。
.root {
-fx-focus-color: transparent;
-fx-faint-focus-color: transparent;
}
#wordsList {
-fx-border-color: transparent;
}Run Code Online (Sandbox Code Playgroud)
这是我的 FXML 代码
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.*?>
<?import h.*?>
<?import javafx.scene.layout.*?>
<Tab xmlns="http://javafx.com/javafx"
xmlns:fx="http://javafx.com/fxml" closable="false">
<text><Constants fx:constant="SECOND_TAB_NAME"/></text>
<HBox>
<ListView fx:id="wordsList" prefWidth="250">
</ListView>
</HBox>
</Tab>Run Code Online (Sandbox Code Playgroud)
我正在尝试动态更改图例的颜色,因此我的 css 类中没有任何线条和符号的样式。我可以动态更改图表中的所有线条和符号,但遗憾的是无法更改图例。他们保持默认状态。有没有办法动态地做到这一点?
所以,我尝试过:
1)
for (int index = 0; index < series.getData().size(); index++) {
XYChart.Data dataPoint = series.getData().get(index);
Node lineSymbol = dataPoint.getNode().lookup(".chart-legend");
lineSymbol.setStyle("-fx-background-color: #00ff00, #000000; -fx-background-insets: 0, 2;\n" +
" -fx-background-radius: 3px;\n" +
" -fx-padding: 3px;");
}
Run Code Online (Sandbox Code Playgroud)
根据 caspian.css 和下面的链接问题,这应该可以工作,但它给了我NullPointerException因为无法找到 .chart-legend 即使它在那里。
2)
for (Node n : lineChart.getChildrenUnmodifiable())
{
if (n instanceof Legend)
{
final Legend legend = (Legend) n;
// remove the legend
legend.getChildrenUnmodifiable().addListener(new ListChangeListener<Object>()
{
@Override
public void onChanged(Change<?> arg0)
{
for (Node node : …Run Code Online (Sandbox Code Playgroud) 我有一个包含不同数据类型字段的对象:
public class MyObject{
private String field1;
private CustomObject field2;
private int field3;
...
}
Run Code Online (Sandbox Code Playgroud)
我想创建一个MyObject具有多个MyObject节点的树视图,每个节点都有字段(field1、field2、field3..etc )作为子节点。
我知道我可以制作一个字符串的 TreeView 并使用 addNode(MyObject obj) 方法自行填充它,在该方法中我将添加我需要的各个 TreeItems。但是,我使用 TableView 执行此操作,其中我能够将列与字段属性绑定。例如:
TableView<MyObject> table;
TableColumn<MyObject, String> myColumn;
myColumn.setCellValueFactory(new PropertyValueFactory<>("field1"));
Run Code Online (Sandbox Code Playgroud)
有什么办法可以为 a 做类似的事情吗TreeView<MyObject>?我不反对创建一个扩展的子类TreeItem<?>
我正在寻找的最终结果将是这样的:
--> First My Object
->field1: "Value at Field 1"
->field2: "Value at Field 2"
->field3: 3
--> Second My Object
->field1: "Value at Field 1"
->field2: "Value at Field 2" …Run Code Online (Sandbox Code Playgroud) 我正在构建一个应用程序,它将根据特定条件显示图像。目前,我的数据显示在 JavaFX 上的表格视图中。我的可观察模型类仅包含有关用户输入信息的信息。我需要比较表视图类中的信息并在称为状态的指定列之一内显示图像。
TableColumn<StudentRecord, ImageView> statusCol = new TableColumn<>("Status");
Run Code Online (Sandbox Code Playgroud)
我遵循了不同的答案,但找不到合适的解决方案。我这样做是为了循环遍历所有对象并显示图标。但这种方法会在每一行上显示图标。
dataController.getAllData().forEach(studentRecord -> {
if (studentRecord.getDate().equalsIgnoreCase("some date")) {
statusCol.setCellValueFactory(c -> new SimpleObjectProperty<ImageView>(new ImageView("/images/tick.png")));
}else{
statusCol.setVisible(false);
}
}
);
Run Code Online (Sandbox Code Playgroud)
我尝试了 StackOverflow 的不同答案,但无法正确实现它。知道如何解决这个问题吗?
用最简单的方式来说,我想根据两个 DatePicker 中选定日期的日期范围来过滤 TableView 中的数据。
有没有办法添加侦听器或类似于在 TextFields 上使用 addListener 的方法,或者是否有更好的方法来解决此问题?我找不到任何解释这一点的教程。
我是否应该只在按下按钮时调用 Postgres 视图来更新表?
在图像中,如果它正常工作,它将仅显示 TID 16 和 17 的行,其中“Opened”列中的日期位于日期范围之间。
我试图在我的公共类中启动在另一个类中定义的应用程序,从而获得“无法构造应用程序实例”异常。下面的示例非常简单。我错过了什么?---线索将非常感激。
这个问题和问题不一样
无法构造 javafx.application.Application 实例
因为我想在单独的类中定义应用程序及其启动。
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.stage.Stage;
public class Main {
public static void main(String[] args) {
Application.launch(OKButton.class, args);
}
}
class OKButton extends Application {
@Override
public void start(Stage stage) {
Button btn = new Button("OK");
Scene scene = new Scene(btn, 200, 250);
stage.setScene(scene);
stage.show();
}
}
Run Code Online (Sandbox Code Playgroud) 有谁知道如何基于 javafx.event 包编写自定义事件调度程序?我在 Google & Co. 中搜索,但没有找到很好的例子。
有人给我一个简约的例子吗?那就太好了 - 我尝试了几次来理解它,但我失败了。