Giter Club home page Giter Club logo

springboot-javafx-support's Introduction

BuildStatus Coverage Status Maven Central ReadTheDocs MIT License

springboot-javafx-support

Attention: The current master is for Spring Boot 2 and Spring Framework 5.

The latest production ready releases:

  • For Spring Boot 1.5.x is 1.4.5. (End of life!)
  • For Spring Boot 2.x is 2.1.6.

Spring Boot and JavaFx - A perfect match!

You will need at least JDK1.8 patch level 40.

!!! Currently not available... Server crashed! Find a step-by-step example here: https://www.felixroske.de/page/programmierung/index.html !!!

And a bunch of examples here: https://github.com/roskenet/spring-javafx-examples/

springboot-javafx-support's People

Contributors

andreasjay avatar dependabot[bot] avatar fbouchedid avatar hzamir avatar krystiankaluzny avatar octaviospain avatar pyknic avatar roskenet avatar slepubin avatar thomasdarimont avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

springboot-javafx-support's Issues

awt support

To display some undecorated and utility windows we need to use AWT. (FX dont provide this) Also we need to have tray icon. (FX dont support it too) The best way for this is usage of AWT. But unfortunately we cant use awt by this way:
final ConfigurableApplicationContext ctx = SpringApplication.run(this.getClass(), savedArgs);
But if we replace it with:
final ConfigurableApplicationContext ctx = new SpringApplicationBuilder(this.getClass()) .headless(false).run(savedArgs);
it should work.

Does not display the icon

Hello, I'm exploring the framework and I think it's very good but there's something I can not solve that has to do with SplashScreen. When defining the application icon in the application.yml, when I run it without the SplashScreen (overwriting the visible method to false), the application icon works, but when I run it with the SplashScreen (overwriting the visible method to true or By default) does not display the icon that you configure in the application.yml, it shows the default of Javafx, maybe something I am doing wrong, please I would like your help. Thank you so much 😃

imgquey2

callback event

Whether there is a callback event after the view is displayed, such as data initialization。

Make launchApp public

Submitted by ~jangalinski

I am trying to get a springboot/JavaFx application to run with kotlin.

but when I do

@SpringBootApplication
class MyApplication : AbstractJavaFxApplicationSupport()

fun main(args: Array<String>)  {
  AbstractJavaFxApplicationSupport.launchApp(MyApp::class.java, MyView::class.java, args)
}

I cannot access the launchAppmethod since it is of protected scope.

Could you change visibility to support this usecase? It's not very useful to have this one protected imho, since the original launch is public, so you are not really hiding implementation details ...

Replace autowired beans in unit tests

I have not found a way to replace the @Autwired Beans by fakes or similar in test cases. Can you please provide a example for this?

My attempt:

@RunWith(SpringRunner.class)
@SpringBootTest
public class NewsViewTest extends GuiTest {

	@MockBean private FakeNewsService fakeService;

	@PostConstruct
	public void init() throws Exception {
		initMocks(this);
		init(NewsView.class);
	}

	@Test
	public void test() {
	}

}
public interface NewsService {

	public ObservableList<Article> getLatestArticle() throws Exception;
	
}
@FXMLController
public class NewsController {

	@FXML private ListView<Article> news;
	@Autowired private NewsService service;

	private ListProperty<Article> binding = new SimpleListProperty<>();

	@FXML
	void initialize() throws Exception {
		assert news != null : "fx:id=\"news\" was not injected: check your FXML file 'helloworld.fxml'.";
		assert service != null : "No rest news service was injected";

		binding.set(service.getLatestArticle());
		news.itemsProperty().bind(binding);

		ItemSelectedListener listener = new ItemSelectedListener(news);
		news.getSelectionModel().selectedItemProperty().addListener(listener);
	}

}

Question about package configuration

Hi there,

I started using your library the other day and read through a tutorial here:

https://www.felixroske.de/page/programmierung/index.html

Had a few issues that seem to be related to file location. The tutorial uses a single package ( example ) for all config, view and controller classes. As well, the resources folder matches the package name. It seems that if I deviate from the package structure at all, the view class cannot locate the associated .fxml file at all. If you have your view class in one package ( say com.myfxapp.config ) and your controller in a different package ( say com.myfxapp.controller ) and the .fxml file in src/main/resources/fxml, how does one configure the path structure ? Or are you limited to needing the same package / folder for all files ? On the annotation I did see that you can set a relative path which was good. Can you do this for the controller as well ? Thanks!

Regards,
Chris

Write proper Java Docs

The project was initially some helper classes used internally in a Zalando project for an internal tool.
Without any proper java docs.

Write them!

Build with maven

When execute my project in intellij Idea run fine, but then build my project with maven and execute i get this error. Only show the splash screen.

Exception in thread "JavaFX Application Thread" java.lang.IllegalStateException: Location is not set.
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2434)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2409)
at de.felixroske.jfxsupport.AbstractFxmlView.loadSynchronously(AbstractFxmlView.java:99)
at de.felixroske.jfxsupport.AbstractFxmlView.ensureFxmlLoaderInitialized(AbstractFxmlView.java:113)
at de.felixroske.jfxsupport.AbstractFxmlView.getView(AbstractFxmlView.java:125)
at de.felixroske.jfxsupport.AbstractJavaFxApplicationSupport.showView(AbstractJavaFxApplicationSupport.java:117)
at de.felixroske.jfxsupport.AbstractJavaFxApplicationSupport.showInitialView(AbstractJavaFxApplicationSupport.java:105)
at de.felixroske.jfxsupport.AbstractJavaFxApplicationSupport.lambda$start$2(AbstractJavaFxApplicationSupport.java:76)
at com.sun.javafx.application.PlatformImpl.lambda$null$173(PlatformImpl.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$174(PlatformImpl.java:294)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$148(WinApplication.java:191)
at java.lang.Thread.run(Thread.java:745)

Move the showView method to AbstractFxmlView

The responsibility of an AbstractFxmlView to be shown should recall on its own, and not on AbstractJavaFxApplicationSupport via a static call.

To show a view, now you have to do it this way

Main.showView(FirstView.class);
  • This makes code hardly testable.
  • This gives the control of showing a class to the Main class (that is nothing special, just the entry point of the application), but an AbstractFxmlView should have the ability to be requested to be shown, and how.

The solution should provide showView methods to AbstractFxmlView so that:

  • There are separation of concerns
  • Code is testable since is easier to mock an instance of a class rather than an static method
  • There are methods that provides ways to show a view, I. e. under which Window, with which Modality, and if the Window should be shown as show or showAndWait

Cannot get Spring context outside a Component

Hi,

How can we get the Spring context outside a @component?
So far it seems that we cannot as AbstractJavaFxApplicationSupport does not provide any access to it.

Eventually we could define a Component that get it by constructor autowired then init a static variable and only then some Util classes (that we do not want to transform to Component) could poll on it until it is not null anymore.

Am I right?

EDIT: I have modified the util class to become a component but still interested to know what you would recommend.

Spring Boot won't boot and doesn't have any output on STDOUT

Hello Felix,

at first: thanks for sharing your implementation of spring boot into javafx as library.

Problem

While starting the application I see the splashscreen and that's it. There's no console output of spring booting.

1. Problem Application does not start
2. Problem There seems to be no console output

e.g. the spring logo:

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::  (v2.0.0.BUILD-SNAPSHOT)

What I already did

Debugging

Debugging showed that execution stops at booting spring context: here

Checking for Exceptions

After debugging my first guess were SpringApplication.run(); is throwing exceptions I can't see on my console output for whatever reason. So I copied your AbstractJavaFxApplicationSupport class and let my Main class extend from this copy. Aaaand we have an output with exception now:

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::  (v2.0.0.BUILD-SNAPSHOT)

2017-06-09 13:33:19.838 INFO  o.s.boot.SpringApplication - Starting application on DEINEMUDDAH with PID 6768 (started by deinemuddah in D:\Projekte\java\wovdb)
2017-06-09 13:33:19.839 INFO  o.s.boot.SpringApplication - No active profile set, falling back to default profiles: default
2017-06-09 13:33:19.868 INFO  o.s.c.a.AnnotationConfigApplicationContext - Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@2e99e190: startup date [Fri Jun 09 13:33:19 CEST 2017]; root of context hierarchy
2017-06-09 13:33:20.415 INFO  o.s.b.f.a.AutowiredAnnotationBeanPostProcessor - JSR-330 'javax.inject.Inject' annotation found and supported for autowiring
2017-06-09 13:33:20.837 INFO  o.s.o.j.LocalContainerEntityManagerFactoryBean - Building JPA container EntityManagerFactory for persistence unit 'default'
2017-06-09 13:33:21.626 INFO  o.s.o.j.LocalContainerEntityManagerFactoryBean - Initialized JPA EntityManagerFactory for persistence unit 'default'
2017-06-09 13:33:22.327 INFO  o.s.boot.SpringApplication - Started application in 2.857 seconds (JVM running for 4.585)
Exception in thread "JavaFX Application Thread" java.lang.IllegalStateException: Location is not set.
	at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2434)
	at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2409)
	at de.felixroske.jfxsupport.AbstractFxmlView.loadSynchronously(AbstractFxmlView.java:173)
	at de.felixroske.jfxsupport.AbstractFxmlView.ensureFxmlLoaderInitialized(AbstractFxmlView.java:190)
	at de.felixroske.jfxsupport.AbstractFxmlView.getView(AbstractFxmlView.java:202)
	at de.argon.wovdb.AbstractSpringJavaFxApp.showView(AbstractSpringJavaFxApp.java:149)
	at de.argon.wovdb.AbstractSpringJavaFxApp.showInitialView(AbstractSpringJavaFxApp.java:125)
	at de.argon.wovdb.AbstractSpringJavaFxApp.lambda$start$2(AbstractSpringJavaFxApp.java:93)
	at com.sun.javafx.application.PlatformImpl.lambda$null$173(PlatformImpl.java:295)
	at java.security.AccessController.doPrivileged(Native Method)
	at com.sun.javafx.application.PlatformImpl.lambda$runLater$174(PlatformImpl.java:294)
	at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
	at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
	at com.sun.glass.ui.win.WinApplication.lambda$null$148(WinApplication.java:191)
	at java.lang.Thread.run(Thread.java:745)

I'm not sure if this exception is also thrown when using the original AbstractJavaFxApplicationSupport class.

Location is not set == View class can not find fxml?

After I set the location to my fxml file into the view class:

@FXMLView(
    value="/fxml/helloworld/helloworld.fxml"
)

I got an running Helloworld app with my copied AbstractJavaFxApplicationSupport class.
Switching back to the original AbstractJavaFxApplicationSupport class from your lib. I got the same problem again. I see the Splashscreen and no console ouput.

Meta Info

  • de.roskenet:springboot-javafx-support:1.3.22
  • Spring Boot version 2.0.0-SNAPSHOT

java.lang.ClassCastException when using non-string properties

This may just be how I am using the API, but currently when I try to use javafx.* properties I get a ClassCastException thrown from PropertyReaderHelper#setIfPresent

For example, my application.yaml looks like this

javafx:
    stage:
        resizable: false

I get the following error when trying to create the stage

Exception in thread "JavaFX Application Thread" java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Boolean
	at de.felixroske.jfxsupport.AbstractJavaFxApplicationSupport$$Lambda$142/489220484.accept(Unknown Source)
	at de.felixroske.jfxsupport.PropertyReaderHelper.setIfPresent(PropertyReaderHelper.java:35)
	at de.felixroske.jfxsupport.AbstractJavaFxApplicationSupport.showView(AbstractJavaFxApplicationSupport.java:141)
	at de.felixroske.jfxsupport.AbstractJavaFxApplicationSupport.showInitialView(AbstractJavaFxApplicationSupport.java:105)
	at de.felixroske.jfxsupport.AbstractJavaFxApplicationSupport.lambda$start$2(AbstractJavaFxApplicationSupport.java:76)
	at de.felixroske.jfxsupport.AbstractJavaFxApplicationSupport$$Lambda$101/1446651899.run(Unknown Source)
	at com.sun.javafx.application.PlatformImpl.lambda$null$170(PlatformImpl.java:295)
	at com.sun.javafx.application.PlatformImpl$$Lambda$50/255090923.run(Unknown Source)
	at java.security.AccessController.doPrivileged(Native Method)
	at com.sun.javafx.application.PlatformImpl.lambda$runLater$171(PlatformImpl.java:294)
	at com.sun.javafx.application.PlatformImpl$$Lambda$49/846097765.run(Unknown Source)
	at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
	at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
	at com.sun.glass.ui.win.WinApplication.lambda$null$145(WinApplication.java:101)
	at com.sun.glass.ui.win.WinApplication$$Lambda$38/1314856651.run(Unknown Source)
	at java.lang.Thread.run(Thread.java:745)

This also happens when trying to use application.properties file with this format:

javafx.stage.resizable=false

Fallback in AbstractFxmlView.getBundleName() is never called

Currently (in master and 1.4.1) de.felixroske.jfxsupport.AbstractFxmlView#getBundleName
returns the value if the bundle attribute regardless of whether it is set or not.
So users have to explicitly declare a bundle if they use internationalized strings in their .fxml markup.
e.g.: @FXMLView(bundle="demo.projects.ui.projects"), etherwise an exception will be thrown:

...
Caused by: javafx.fxml.LoadException: No resources specified.
/home/tom/dev/repos/gh/thomasdarimont/spring-labs/springboot-javafx-support-jpa-demo/target/classes/demo/projects/ui/projects.fxml:15

	at javafx.fxml.FXMLLoader.constructLoadException(FXMLLoader.java:2597) ~[jfxrt.jar:na]
	at javafx.fxml.FXMLLoader.access$100(FXMLLoader.java:103) ~[jfxrt.jar:na]
	at javafx.fxml.FXMLLoader$Element.resolvePrefixedValue(FXMLLoader.java:421) ~[jfxrt.jar:na]
	at javafx.fxml.FXMLLoader$Element.processValue(FXMLLoader.java:363) ~[jfxrt.jar:na]
	at javafx.fxml.FXMLLoader$Element.processPropertyAttribute(FXMLLoader.java:325) ~[jfxrt.jar:na]
	at javafx.fxml.FXMLLoader$Element.processInstancePropertyAttributes(FXMLLoader.java:235) ~[jfxrt.jar:na]
	at javafx.fxml.FXMLLoader$ValueElement.processEndElement(FXMLLoader.java:767) ~[jfxrt.jar:na]
	at javafx.fxml.FXMLLoader.processEndElement(FXMLLoader.java:2823) ~[jfxrt.jar:na]
	at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2532) ~[jfxrt.jar:na]
	at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2441) ~[jfxrt.jar:na]
	at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2409) ~[jfxrt.jar:na]
	at de.felixroske.jfxsupport.AbstractFxmlView.loadSynchronously(AbstractFxmlView.java:159) ~[springboot-javafx-support-1.4.1.jar:na]
	... 12 common frames omitted

It seems that this check if (!StringUtils.isEmpty(annotation)) {
in de.felixroske.jfxsupport.AbstractFxmlView#getBundleName is wrong.

It should rather be if (!StringUtils.isEmpty(annotation.bunde())) {

First FXMLView has long delay to load because of after spring applicationContext loaded

When we open this application, user wait long time for spring loading. User hasn't identify what happened in between for the long delay. So This is better to use, LauncherImpl for splash screen as a PreLoader or
https://gist.github.com/jewelsea/1588531

Usage:
protected static void launchApp(Class<? extends AbstractJavaFxApplicationSupport> appClass,
Class<? extends AbstractFxmlView> view, String[] args, boolean hasSplashScreen);
hasSplashScreen : true - display splash screen when spring loading, false - implemented

Spring environment variables:
javafx.splashscreen.image=splash.jpg
javafx.splashscreen.text=Spring Loading...

Fail to launch with Spring boot 2.0.0.M4

Hi,

Same app works with Spring boot 1.5.2.RELEASE

Fail to launch with error:
10:37:21.838 [ForkJoinPool.commonPool-worker-1] ERROR de.felixroske.jfxsupport.AbstractJavaFxApplicationSupport - Failed to load spring application context:
java.util.concurrent.CompletionException: java.lang.NoSuchMethodError: org.springframework.boot.SpringApplication.run(Ljava/lang/Object;[Ljava/lang/String;)Lorg/springframework/context/ConfigurableApplicationContext;
at java.util.concurrent.CompletableFuture.encodeThrowable(CompletableFuture.java:273)
at java.util.concurrent.CompletableFuture.completeThrowable(CompletableFuture.java:280)
at java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1592)
at java.util.concurrent.CompletableFuture$AsyncSupply.exec(CompletableFuture.java:1582)
at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289)
at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056)
at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692)
at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157)
Caused by: java.lang.NoSuchMethodError: org.springframework.boot.SpringApplication.run(Ljava/lang/Object;[Ljava/lang/String;)Lorg/springframework/context/ConfigurableApplicationContext;
at de.felixroske.jfxsupport.AbstractJavaFxApplicationSupport.lambda$init$1(AbstractJavaFxApplicationSupport.java:100)
at java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1590)
... 5 common frames omitted

Load css in the Scene

Hi, how can I do to load only once the css to the General Scene (AbstractJavaFxApplicationSupport) ?, instead of declaring it in all my views @FXMLView (css = {"..."}). Since my intention is that all views use the same css. Thank you so much :)

Error message dialog if creating main controller failed

I have MainWindowController which control MainWindowView.
MainWindowView class is an argument of launchApp static method.

@FXMLController
public class MainWindowController
{
	@PostConstruct
	private void initBean()
	{
            doSomething()
	}

	@FXML
	public void initialize()
	{
	     doSomething2()
	}
}

If doSomething or doSomething2 throw RuntimeException then application stuck on the SplashScreen.

The first case is caused by SpringApplication.run(this.getClass(), savedArgs) failed in init().
The second is caused by view.getView() failed in showView(Class<? extends AbstractFxmlView> newView)

I think that it would by more informative to show some error dialog or even close the app.

Use specified icons in application.yml for all views

At this moment the icons that are specified in the application.yml file in this way

javafx:
  appicons:
    - /icons/icon_16x16.png
    - /icons/icon_24x24.png
    - /icons/icon_36x36.png
    - /icons/icon_42x42.png
    - /icons/icon_64x64.png

are only used for the first view/stage that is loaded when calling

launchApp(MyJavaFxApplication.class, StartView.class, new SplashScreen(), args);

When other views are loaded, the specified icons are not set for the correspondent stage.

This could be done by getting the icons via GUIState.getStage().getIcons() when constructing the Stage in AbstractFxmlView and therefore the icons would be used for all the views.

How change View for specific container in the controller?

First of all, I would like to thank for a wonderful addition to Spring.
I know that it is possible to change the View of the whole window by
Main.showView(SomeView.class);
But how can I change it only for a specific container in the controller?
E.g.
@FXMLController public class MainWindowController { @FXML private AnchorPane anchorPane; }

public class ScreensManager { public void showOtherWindow() { Parent rootNode= (Parent) load(Other.class); mainWindowController.getAnchorPane().getChildren().clear(); mainWindowController.getAnchorPane().getChildren().add(rootNode); } }

hideView

There's the convenience method

public static void showView(Class<? extends AbstractFxmlView> window, Modality mode)

Shouldn't there also be one to hide or close it?

Fails to load when running jar directly

I have been unable to run jar directly, though running it via maven with the spring-boot:run target works fine (or running via ide). The stack trace is as follows. Not that while the message ostensibly complains about not loading the spring application context, see the "Not on FX Application Thread" message further down.

E 23:36:04.145 ort.AbstractJavaFxApplicationSupport - Failed to load spring application context:
java.util.concurrent.CompletionException: java.lang.NullPointerException
at java.util.concurrent.CompletableFuture.encodeThrowable(CompletableFuture.java:273)
at java.util.concurrent.CompletableFuture.completeThrowable(CompletableFuture.java:280)
at java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1592)
at java.util.concurrent.CompletableFuture$AsyncSupply.exec(CompletableFuture.java:1582)
at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289)
at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056)
at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692)
at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157)
Caused by: java.lang.NullPointerException: null
at de.felixroske.jfxsupport.AbstractJavaFxApplicationSupport.lambda$null$0(AbstractJavaFxApplicationSupport.java:105)
at java.util.ArrayList.forEach(ArrayList.java:1249)
at de.felixroske.jfxsupport.AbstractJavaFxApplicationSupport.lambda$init$1(AbstractJavaFxApplicationSupport.java:105)
at java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1590)
... 5 common frames omitted
Exception in thread "JavaFX Application Thread" java.lang.IllegalStateException: Not on FX application thread; currentThread = JavaFX Application Thread
at com.sun.javafx.tk.Toolkit.checkFxUserThread(Toolkit.java:236)
at com.sun.javafx.tk.quantum.QuantumToolkit.checkFxUserThread(QuantumToolkit.java:423)
at javafx.stage.Window.setShowing(Window.java:921)
at javafx.stage.Window.hide(Window.java:947)
at com.sun.javafx.stage.WindowPeerListener.closed(WindowPeerListener.java:100)
at com.sun.javafx.tk.quantum.GlassWindowEventHandler.run(GlassWindowEventHandler.java:119)
at com.sun.javafx.tk.quantum.GlassWindowEventHandler.run(GlassWindowEventHandler.java:40)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.tk.quantum.GlassWindowEventHandler.lambda$handleWindowEvent$423(GlassWindowEventHandler.java:151)
at com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:389)
at com.sun.javafx.tk.quantum.GlassWindowEventHandler.handleWindowEvent(GlassWindowEventHandler.java:149)
at com.sun.glass.ui.Window.handleWindowEvent(Window.java:1266)
at com.sun.glass.ui.Window.notifyDestroy(Window.java:1183)

Load Spring Context within JavaFx Thread or not ?

This is more to start a discussion:

  • At the beginning the spring context was loaded from the javafx thread. That was nice but generates 2 concerns

    • You'll load some none non UI beans into graphic thread. That's could take some times and liekly not relevant.
    • It was more or less impossible to use splashscreen (with progress feedback) when your spring ctx loading take time (due to previous point)
  • Then Spring Ctx is now loaded from another thread that generate other concerns (even if now splash-screen is working fine)

    • All @FXMLView / Controller are loaded by spring (they are flagged as @component)
      • Meaning all UI are loaded by a non graphic thread (not sure it's a best practice)
    • We are struggled when u want to used WebEngine or GlyphFont (controlsfx) because there are checking in their constructor to be instantiate by JavaFx thread.

There is pro and cons in both solution
I don't know how to solve that properly.
Right now I did a dirty hack: where I instantiate some UI bean by delegating to JavaFx thread and blocking current thread until it's finished :-(

Any views ?

View cannot be loaded if the name is only 'View'

While writing a One Page JavaFX application, I noticed that a View named 'View' can not be loaded. The application then crashes with a IllegalStateException.

Stacktrace:

java.lang.IllegalStateException: Cannot load 
	at de.felixroske.jfxsupport.AbstractFxmlView.loadSynchronously(AbstractFxmlView.java:161) ~[springboot-javafx-support-1.4.0.jar:na]
	at de.felixroske.jfxsupport.AbstractFxmlView.ensureFxmlLoaderInitialized(AbstractFxmlView.java:176) ~[springboot-javafx-support-1.4.0.jar:na]
	at de.felixroske.jfxsupport.AbstractFxmlView.getView(AbstractFxmlView.java:188) ~[springboot-javafx-support-1.4.0.jar:na]
	at de.felixroske.jfxsupport.AbstractJavaFxApplicationSupport.showView(AbstractJavaFxApplicationSupport.java:202) [springboot-javafx-support-1.4.0.jar:na]
	at de.felixroske.jfxsupport.AbstractJavaFxApplicationSupport.showInitialView(AbstractJavaFxApplicationSupport.java:177) [springboot-javafx-support-1.4.0.jar:na]
	at de.felixroske.jfxsupport.AbstractJavaFxApplicationSupport.lambda$start$4(AbstractJavaFxApplicationSupport.java:144) [springboot-javafx-support-1.4.0.jar:na]
	at com.sun.javafx.application.PlatformImpl.lambda$null$173(PlatformImpl.java:295) ~[jfxrt.jar:na]
	at java.security.AccessController.doPrivileged(Native Method) ~[na:1.8.0_131]
	at com.sun.javafx.application.PlatformImpl.lambda$runLater$174(PlatformImpl.java:294) ~[jfxrt.jar:na]
	at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95) ~[jfxrt.jar:na]
	at com.sun.glass.ui.win.WinApplication._runLoop(Native Method) ~[jfxrt.jar:na]
	at com.sun.glass.ui.win.WinApplication.lambda$null$148(WinApplication.java:191) ~[jfxrt.jar:na]
	at java.lang.Thread.run(Unknown Source) ~[na:1.8.0_131]
Caused by: java.lang.IllegalStateException: Location is not set.
	at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2434) ~[jfxrt.jar:na]
	at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2409) ~[jfxrt.jar:na]
	at de.felixroske.jfxsupport.AbstractFxmlView.loadSynchronously(AbstractFxmlView.java:159) ~[springboot-javafx-support-1.4.0.jar:na]
	... 12 common frames omitted

Cause:
The AbstractFxmlView tries to resolve the fxml path by itself if its not set by the annotation and thereby cuts 'View' out of the path. The path of a view called 'View' then will point to the parent directory.

private static String stripEnding(final String clazz) {

	if (!clazz.endsWith("view")) {
		return clazz;
	}

	return clazz.substring(0, clazz.lastIndexOf("view"));
}

Support i18n-resource bundles with other encodings than ISO-8859-1

When translating applications to other languages than English, it is common to have characters outside the English alphabet. Since JavaFX default to using ISO-8859-1 when loading a resource bundle, it means that you would have to escape these characters using \uXXXX when doing the translation. A better option would be to expand the @FXMLView-annotation to take an optional parameter encoding so that the correct encoding for the resource bundle can be specified.

Current translation (example_sv.properties):

ongoing: Pågående

Current apperance (without escaping characters):
encoding_before

With escaped characters (example_sv.properties):

ongoing: P\u00E5g\u00E5ende

Apperance when escaped:
encoding_after

The format of annotate is not uniform

@FXMLView(value = "./helloworld.fxml", css = {"./test.css"}, bundle = "com.example.demo.helloworld")

@FXMLView Annotate has 3 property, value, css, bundle, but there are some formatting problems.

I need to provide a suffix for value and css,, however, no for bundle. In fact, for value, css, the properties need file path, the bundle needs different ways(java package manage).

So, can you do something to unify the format.

Last, It's a very good package for javafx & spring boot! Thanks!

Duplicate Code in Tag v1.4.4

AbstractJavaFxApplicationSupport has duplicate lines of code that is causing the beforeShowingSplash to be called twice. I have created a fork and made the modifications. The only issue is that I am not able to create a pull request since there are two paths the 1.4.X and 2.0.X and master is currently on 2.0.X.

Here is a link to the commit on my fork:
https://github.com/fbouchedid/springboot-javafx-support/commit/2f2d361d5cce26c2af3fe3ec766534182561b30a
and I also fixed tabbing in a later commit:
https://github.com/fbouchedid/springboot-javafx-support/commit/89e2732c265543268629c0d087f392b20f629f49

Can you create a v1.4.5 release and merge my branch:
https://github.com/fbouchedid/springboot-javafx-support/tree/bug/remove-duplicate-code

Let me know if there is anything else you need from my end. Thanks!

Add Events to Controller on multiple windows

Hi

First I want to thank you for the great Project.

I am not sure this is the correct place for this question, when not sorry about the circumstances.

I use then new showView method (implement with 1.3.30) and call the new window like this.

App.showView(SettingsView.class, Modality.WINDOW_MODAL);

This works fine but i need to add some window events to the stage because everytime when i show the window i have to update my data. I try the to implement the flowing code in the controller but i have no idea where i can call this method.

`
public void addEvents() {
Window window = vbox.getScene().getWindow();

    window.setOnShowing(this::showingWindowAction);
    window.setOnShown(this::shownWindowAction);
}

`

Thank you
Patric

Setting Scene RIGHT TO LEFT Orientation

Trying to apply RIGHT TO LEFT Orientation to the scene objects by adding :
Main.getScene().setNodeOrientation(NodeOrientation.RIGHT_TO_LEFT);
in Main but not worked

Can I get the root Pane from the primary stage?

Firstly thanks for contribute this awesome project.
I have a main page call player.fxml which is a BorderPane.Something like this

<BorderPane xmlns="http://javafx.com/javafx"
            xmlns:fx="http://javafx.com/fxml"
            fx:controller="cn.will.controller.PlayerController"
            fx:id="root"
            prefHeight="670.0" prefWidth="1020.0" stylesheets="@../css/player.css">
    <top>
        <fx:include source="titleBar.fxml"/>
    </top>
    <left>
        <fx:include source="userLeft.fxml"/>
    </left>
    <center>
        <fx:include source="albumDetail.fxml"/>
    </center>
    <bottom>
        <fx:include source="playBar.fxml"/>
    </bottom>
</BorderPane>

In the Main.class I launch the app.

@SpringBootApplication
public class Main extends AbstractJavaFxApplicationSupport implements ApplicationContextAware{

    private static BorderPane root;

    @Autowired
    private ApplicationContext applicationContext;

    public static void main(String[] args) {
        launchApp(Main.class, PlayerView.class, new BlueprintSplashScreen(),args);
    }

    @Override
    public void start(Stage stage) throws Exception {
        super.start(stage);
        stage.getIcons().add(new Image("img/music-icon32.png"));
    }

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        this.applicationContext = applicationContext;
    }

   // ignore this. It's something I tried to meet my requirement.
   //I  try to use         
   //PlayerView view = applicationContext.getBean(PlayerView .class);
   //root = (BorderPane) view.getView();
   //but it throws NullPointerException dor applicationContext, it seems inject fail
    public ApplicationContext getApplicationContext() {
        return applicationContext;
    }
}

I want to change the center content in the BorderPane dynamically.I really need to get this BorderPane so I can change it.
BTW,I also use Main.showView(xxx.class),but I just want to change the center.Not a whole stage.
Thanks a lot advanced.

Concurrency Bug in AbstractJavaFxApplicationSupport

In AbstractJavaFxApplicationSupport, there appears to be a concurrency issue. On line 166, there is a synchronize-statement that doesn't do anything unless multiple threads are invoking the start(Stage)-method at the same time. It doesn't prevent appCtxLoaded from being modified outside the synchronized block, which is the case in launchApplicationView.

synchronized (this) { // This does not prevent other threads from modifying appCtxLoaded from a different method!!
    if (appCtxLoaded.get()) { 
        // Spring ContextLoader was faster
        Platform.runLater(showMainAndCloseSplash);
    } else {
        appCtxLoaded.addListener((ov, oVal, nVal) -> {
            Platform.runLater(showMainAndCloseSplash);
        });
    }
}

The correct way of doing this would be to remove the synchronized-statement, change the BooleanProperty to a CompletableFuture that completes once the splash-message is showing and then close the splash once both the "splash is showing" and "context is loaded" conditions are satisfied.

Not populating @FXML fields on initialize method

Initializable controllers is not populating @FXML annotated fields, see example:

@FXMLController
public class Helloworld implements Initializable  {
    @FXML
    private Label helloLabel;

    @FXML
    private TextField nameField;

    @FXML
    private void setHelloText(final Event event) {
        final String textToBeShown = nameField.getText();
        helloLabel.setText(textToBeShown);
    }

    @FXML
    @Override
    public void initialize(URL location, ResourceBundle resources) {
        nameField.setText("Testing..."); //NPE, cause nameField is null
    }
}

How do you make exe executable files?

I need to SpringBoot-JavaFx the project into a exe executable file, but in the use of the exe4j package can run. What is the solution?
Error is as follows:
Caused by: java.lang.IllegalArgumentException: No auto configuration classes found in META-INF/spring.factories. If you are using a custom packaging, make sure that file is correct.

Example for passing parameters into controller of sub-control

Hello,

I am missing an example of how I can pass values into a controller. I do not really get to see the controller when using this tool, right?

Could you maybe help me to give an idea of how to still be able to pass values into the controller from a parent controller? (Example: I have a list where I select one item and now want to display more detailed info about this specific entry in a new window).

Main purpose of @FXMLView (doc)

Hi,
I start using you library in enterprise project. It's realy time saving and great, but I have a problem of understanding the difference between @FXMLController and @FXMLView. Should I split the code way like actions and listeners into controller and creating dynamic content etc into view ?
Thanks

Application Context when creating a new Stage

Great library roskent! Excellent work.

I have an issue that if I create another stage away from the main stage, like a modal, then the modal is not aware of the application context.

I changed the example part-6-2 to illustrate:

`@FXMLController
public class ViewController {

public void showFirstView(Event event) {
    Main.showView(FirstView.class);
    System.out.println("clicked");
}

public void showSecondView(Event event) throws IOException {
    //Main.showView(SecondView.class);
    Parent root = FXMLLoader.load(ViewController.class.getResource("second.fxml"));
    Scene scene = new Scene(root);
    Stage stage = new Stage();
    stage.setScene(scene);
    stage.show();
}

}`

In this case, when I click First View button in then new Second View Stage, nothing happens.

Any advise as to how to go about solving this?

API for alternative controller class

Please provide an API to be able to set custom controller class for a view. The purpose of this is to be able to reuse fxmls with different controllers.

Possible implementations:

  1. extend @FXMLView with a controllerClass field
  2. expose fxml loader creation so the loader can be built with custom code

Thanks!

Two stage in the same application.

Is it possible to handle two stage in the application? Basically, what I am trying to do is display two windows after the startup of the app.
Sorry, I am a newbie with JavaFX.
Thanks in advance.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.