Tag: javafx

你如何模拟JavaFX工具包初始化?

[序言:道歉,这里有很多代码,其中一些代码可能与此问题无关,而某些代码对于理解问题可能缺失; 请评论,我会相应地编辑问题。] 环境:Ubuntu 14.10 x86_64; Oracle JDK 1.8u25。 unit testing库是TestNG,版本6.8.13; Mockito是版本1.10.17。 在我的GUI应用程序中,JavaFX称之为“控制器”的东西是非常被动的,因为这个“控制器”(我称之为“显示器”)真正做的唯一事情就是发送事件。 现在,当收到需要GUI更新的事件时,它是另一个类,我称之为视图,它负责更新GUI。 简而言之: 显示 – >演示者 – >视图 – >显示 我有两个unit testing: 显示 – >主持人; 主持人 – >查看。 所以,我在这方面已经被覆盖了(我可以改变显示器的优势,这就是我这样做的原因)。 但现在我尝试测试“视图 – >显示”部分; 我是SOL。 作为说明,这里是视图类: @NonFinalForTesting public class JavafxTreeTabView extends JavafxView implements TreeTabView { private final BackgroundTaskRunner taskRunner; public JavafxTreeTabView(final BackgroundTaskRunner taskRunner) throws IOException { […]

BufferedImage to JavaFX image

我有一个从主显示器截取的图像,我想将它添加到Java FX ImageView如下所示: @FXML protected ImageView screenshot() throws AWTException, IOException { Rectangle screenRect = new Rectangle(Toolkit.getDefaultToolkit().getScreenSize()); BufferedImage capture = new Robot().createScreenCapture(screenRect); ImageView imageView = new ImageView(); Image image = capture; //Error imageView.setImage(image); return imageView; } 我正在尝试将BufferedImage capture设置为javafx.scene.image.Image image但类型不兼容,我也无法投射它。 我怎么能纠正这个?

有条件的颜色背景JavaFX LineChart

我希望有条件地改变折线图的背景颜色。 在给定的示例中,我正在修改图表,以便Y值> = 3的任何部分在后台显示为红色阴影: LineChartJavaFXTest.java import javafx.application.Application; import javafx.scene.Scene; import javafx.scene.chart.LineChart; import javafx.scene.chart.NumberAxis; import javafx.scene.chart.XYChart; import javafx.stage.Stage; public class LineChartJavaFXTest extends Application { @Override public void start(Stage stage) { stage.setTitle(“Line Chart Sample”); //defining the axes final NumberAxis xAxis = new NumberAxis(); final NumberAxis yAxis = new NumberAxis(); xAxis.setLabel(“Seconds”); yAxis.setLabel(“Volume”); //creating the chart final LineChart lineChart […]

在JavaFX 8中管理multithreading的最佳方法是什么?

我正在尝试使用multithreading来找到影响JavaFX GUI元素的形状和内容的有效方法,例如简单的Pane 。 假设我有一个简单的Pane ,我在给定的时间点上显示填充的Circle ,我想要有可能回答它们,例如通过敲击相应的键。 到目前为止,为此目的,我尝试使用类与Runnable接口的实现并在其中创建经典的Thread对象,以便从外部JavaFX Pane添加和/或删除元素,这些元素被传递给那个“线程类” “在其主要Application类的构造函数参数中。 比如,两个类,1)应用程序和2)线程类,看起来像这样: import javafx.application.Application; import javafx.scene.Parent; import javafx.scene.Scene; import javafx.scene.layout.BorderPane; import javafx.scene.layout.Pane; import javafx.scene.paint.Color; import javafx.scene.shape.Circle; import javafx.stage.Stage; public class ClassApplication extends Application { private Pane pane; public Parent createContent() { /* layout */ BorderPane layout = new BorderPane(); /* layout -> center */ pane = new […]

如何分析传入消息(Android上的JavaFX)

我将我的JavaFX应用程序移植到我的Android设备上。 我希望我的应用程序读取传入的SMS消息并将其存储在数据库中。 我在StackOverflow中发现了几个问题,但我不知道如何在JavaFX方法中实现。 请帮忙!

如何理解JavaFX三角网格?

只是试图理解JavaFX文档重新三角形网格。 此代码可以工作并绘制一个矩形。 public class Shape3DRectangle extends TriangleMesh { public Shape3DRectangle(float Width, float Height) { float[] points = { -Width/2, Height/2, 0, // idx p0 -Width/2, -Height/2, 0, // idx p1 Width/2, Height/2, 0, // idx p2 Width/2, -Height/2, 0 // idx p3 }; float[] texCoords = { 1, 1, // idx t0 1, 0, // […]

具有幻灯片效果的JavaFX Switch场景

可以用幻灯片效果切换场景吗? 我希望当我在舞台实例上调用setScene时,它会使用幻灯片效果更改场景。 这是可能的? public class ManyScenes extends Application { public static void main(String[] args) { Application.launch(args); } @Override public void start(final Stage primaryStage) { primaryStage.setTitle(“Slide”); Group root1 = new Group(); Group root2 = new Group(); Scene scene1 = new Scene(root1, 300, 250); Scene scene2 = new Scene(root2, 300, 250); Rectangle rectangle2 = new Rectangle(300, 250); […]

将两个tableviews绑定在一起,以便它们同步滚动

我想将两个tableviews绑定在一起,以便它们同步滚动。 我怎么做? 我无法找到如何访问tableview的滚动条。

使用JFXPanel Swing interop防止JavaFX线程死亡?

我将几个JFXPanels嵌入到Swing应用程序中,当JFXPanel不再可见时,JavaFX线程就会死掉。 这是有问题的,因为在JavaFX线程死后创建另一个JFXPanel将不会启动另一个JavaFX线程,因此JFXPanel将为空。 据我所知,JFXPanel ctor通过调用以下命令启动JavaFX线程: PlatformImpl.startup(new Runnable() { @Override public void run() { // No need to do anything here } }); 稍后,一旦JFXPanel具有父组件,就会调用其addNotify方法,该方法调用registerFinishListener ,该方法使用PlatformImpl注册PlatformImpl.FinishListener() 。 注册FinishListener的行为可防止JavaFX线程在调用PlatformImpl.checkIdle()时死亡。 当JFXPanel不再可见时,其removeNotify方法是调用deregisterFinishListener()调用: private synchronized void deregisterFinishListener() { if (instanceCount.decrementAndGet() > 0) { // Other JFXPanels still alive return; } PlatformImpl.removeListener(finishListener); finishListener = null; } 当instanceCount为零时, FinishListener被删除,导致PlatformImpl.tkExit在以下代码中调用PlatformImpl.tkExit ,导致JavaFX线程死亡: private static void notifyFinishListeners(boolean […]

自动填充Java中的WebView字段

所以这是我的问题。 我正在使用JavaFX中的WebView类。 我想要做的是,我希望webview中加载的字段自动填充存储在数组中的信息。 可能吗? 提前致谢