我有自定义ListView单元格我有两个控件的HBox:
例如,我设置类别字段的ListView项数组,如果字段类型为布尔我创建CheckBox,如果字符串我创建TextField等.
问题是:我只在方法updateItem()中获取Field对象 - 只有在那里我才能创建我的控件.
在JavaFX 7中一切正常,但在Java 8上 - 我没有看到我的控件.
是否存在解决我案件的正确方法?
更新1
这里是复制问题的完整示例:
package javafx8listviewexample;
import java.lang.reflect.Field;
import java.net.URL;
import java.util.Date;
import java.util.ResourceBundle;
import javafx.collections.FXCollections;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.DatePicker;
import javafx.scene.control.ListCell;
import javafx.scene.control.ListView;
import javafx.scene.control.TextField;
import javafx.scene.control.cell.TextFieldListCell;
import javafx.util.Callback;
/**
*
* @author dmitrynelepov
*/
public class FXMLDocumentController implements Initializable {
static class TestClassForListView {
public String fieldString;
public Date fieldDate;
}
static class MyListCell extends ListCell<Field> {
/**
* As in tutorial
* …Run Code Online (Sandbox Code Playgroud) 当任何表中没有记录时,它会显示一条消息"表中没有内容",这默认是JavaFx中TableView的功能.
所以我的问题是,JavaFx中的ListView是否可以实现相同的目标?就像,如果任何ListView中没有项目,那么它将显示与TableView相同的消息,而不是空白/空字段.
是否可以将整个样式表包装在字符串中并将其应用于某个节点?用例是为PseudoClass添加特定(非变化)行为.我知道我可以使用pane.getStylesheets().add(getClass().getResource("mycss.css").toExternalForm());,但我想知道是否有某种方法可以直接将其嵌入源代码中; 一些事情:
pane.getStylesheets().add(
".button:ok { -fx-background-color: green; }\n"+
".button:ko { -fx-background-color: red; }");
Run Code Online (Sandbox Code Playgroud) 我正在使用它
import java.util.Random;
import java.util.Timer;
import java.util.TimerTask;
import javafx.application.Application;
import javafx.application.Platform;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.paint.Color;
import javafx.scene.shape.Circle;
import javafx.stage.Stage;
public class Main extends Application {
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage primaryStage) {
Group root = new Group();
Scene scene = new Scene(root, 600, 400);
primaryStage.setScene(scene);
Circle circle = new Circle(300,200,50, Color.BLACK);
primaryStage.setTitle("Circle");
primaryStage.setResizable(false);
root.getChildren().add(circle);
moveCircle(circle, scene);
primaryStage.show();
}
public int random(int min, int max) {
return new Random().nextInt((max - min) + …Run Code Online (Sandbox Code Playgroud) 可以说,我们有以下课程:
import javafx.application.Application;
import javafx.stage.Stage;
public class Test extends Application
{
public Test()
{
System.out.println("Constructor");
}
@Override
public void start(Stage primaryStage) throws Exception
{
System.out.println("start");
}
public static void main(String... args)
{
System.out.println("main");
}
}
Run Code Online (Sandbox Code Playgroud)
它源自Application但不使用任何方法.通常通过launch(args)在main中调用来启动JavaFX应用程序.
当我启动这个程序时,唯一的输出是"main",因此不会调用构造函数和start,但程序不会因为运行JavaFX Application线程而终止.但是它来自哪里?
我做了一些调试,发现在main方法运行之前,线程是从主线程启动的.堆栈跟踪以NativeMethodAccessorImpl.
为了更加奇怪:当我从另一个类启动main方法时,JavaFX Application线程没有启动:
public class Test2
{
public static void main(String[] args)
{
Test.main(args);
}
}
Run Code Online (Sandbox Code Playgroud)
那么这是什么样的黑魔法呢?
当我在JavaFX中创建我的第一个3D游戏时 - 您可以使用鼠标从零件组装船只.这提出了一个问题,因为JAVAFX似乎没有用于将PerspectiveCamera屏幕2D坐标转换为场景3D空间的原生元素.
这是我正在努力实现的目标.鼠标移动的块应在假想的平面上移动,该平面始终相对于摄像机旋转90°:
我试图用三角函数解决问题而没有太大的成功.我没有附加代码片段,因为我正在寻找更通用的数学解决方案,但如果需要,我会提供它.
所有帮助将不胜感激!
期望的结果:


这是代码:
package sample;
import javafx.beans.Observable;
import javafx.beans.property.IntegerProperty;
import javafx.beans.property.SimpleIntegerProperty;
import javafx.collections.FXCollections;
import javafx.collections.ListChangeListener;
import javafx.collections.ObservableList;
import javafx.util.Callback;
import java.util.List;
/**
* Created by IDEA on 28/07/15.
*/
public class ListUpdateTest {
public static void main(String[] args) {
Callback<IntegerProperty, Observable[]> extractor = (IntegerProperty p) -> {
System.out.println("The extractor is called.");
Observable[] res = new Observable[]{p};
System.out.println("Result from extractor: " + res);
return res;
};
ObservableList<IntegerProperty> list = FXCollections.observableArrayList(extractor);
System.out.printf("Before adding");
IntegerProperty p1 = new SimpleIntegerProperty(10);
IntegerProperty p2 = new SimpleIntegerProperty(20);
list.addAll(p1, …Run Code Online (Sandbox Code Playgroud) Java Swing具有GridLayout允许您指定小部件数组(如3X4)的大小.小部件然后填充他们占据的面板.你如何在JavaFX中获得类似的效果?
我的视图控制器有一个FileChooser用于打开和保存文件的实例.
每当我调用showOpenDialog()或showSaveDialog()从该实例调用时,我希望生成的对话框与我上次调用其中一个时离开它时位于同一目录中.
相反,每次我调用其中一个方法时,对话框都会在用户主目录中打开.
如何使对话框的"当前目录"在不同的调用中保持不变?
当前行为的示例:
import java.io.File;
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.layout.VBox;
import javafx.stage.FileChooser;
import javafx.stage.Stage;
/**
* Demonstrates the use of an open dialog.
*
* @author N99x
*/
public class FileChooserTest extends Application {
private final FileChooser open = new FileChooser();
private File lastOpened = null;
@Override
public void start(Stage primaryStage) {
Label lbl = new Label("File Opened: <null>");
lbl.setPadding(new Insets(8)); …Run Code Online (Sandbox Code Playgroud) 我只想从JavaFX图表API生成图表图像.我不想显示应用程序窗口,也不想启动应用程序(如果没有必要).
public class LineChartSample extends Application {
private List<Integer> data;
@Override public void start(Stage stage) {
stage.setTitle("Line Chart Sample");
final CategoryAxis xAxis = new CategoryAxis();
final NumberAxis yAxis = new NumberAxis();
xAxis.setLabel("Month");
final LineChart<String,Number> lineChart =
new LineChart<String,Number>(xAxis,yAxis);
lineChart.setTitle("Stock Monitoring, 2010");
XYChart.Series series = new XYChart.Series();
series.setName("My portfolio");
series.getData().add(new XYChart.Data("Jan", 23));
series.getData().add(new XYChart.Data("Feb", 14));
Scene scene = new Scene(lineChart,800,600);
lineChart.getData().add(series);
WritableImage image = scene.snapshot(null);
ImageIO.write(SwingFXUtils.fromFXImage(image, null), "png", chartFile);
//stage.setScene(scene);
//stage.show();
}
public static void main(String[] args) {
launch(args);
}
public …Run Code Online (Sandbox Code Playgroud) javafx-8 ×10
java ×6
javafx ×6
javafx-2 ×4
listview ×2
3d ×1
css ×1
filechooser ×1
javafx-3d ×1
layout ×1
mouse ×1
raycasting ×1
resources ×1
stylesheet ×1