scalafx | ScalaFX simplifies creation of JavaFX-based user interfaces
kandi X-RAY | scalafx Summary
kandi X-RAY | scalafx Summary
ScalaFX version number has two part. The first part corresponds to the latest JavaFX version it was tested with. The second part is an incremental release number. For instance, version 15.0.1-R20 means that it was tested with JavaFX version 15.0.1 and that is the 20th release of ScalaFX.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of scalafx
scalafx Key Features
scalafx Examples and Code Snippets
Community Discussions
Trending Discussions on scalafx
QUESTION
Hi guys this is my first question, so feel free to give constructive criticism.
I am making a space shooter game with ScalaFX and I'm facing a problem where when I am drawing the bullet laser
in my AnimationTimer
loop, whenever the player shoots another bullet, the program only renders the newest bullet and the old bullet just disappears.
For the sake of brevity, I'm going to post the main AnimationTimer
loop related to the bullet input and rendering only:
ANSWER
Answered 2021-Jul-14 at 05:56Ok I solved it, it wasn't a problem with GraphicsContext but rather due to the fact, Laser
is instantiated with the same Sprite
in player.shoot(), therefore all Laser
s will have the same X and Y, and be overlapped, thus appearing as if it "disappeared".
The new code instantiates a new Sprite
everytime Laser
is instantiated as follows:
QUESTION
I created a TiteldPane in scalafx
...ANSWER
Answered 2021-May-05 at 03:02I actually get two errors when I execute sbt run
on your code, and I do not get a deprecation error:
QUESTION
This is the background for my question:
I have a GUI with an accordion with many TitledPanes, and each Titledpane contains a spreadsheetView from the controlsFX package. There is a search-function in the code, where a Titledpane is opened and a specific cell in the spreadsheetView is opened for text input using the edit method of the spreadsheetcell type.
If the TitledPane is already open, this works fine, but if it must open first then the call of the edit-method fails. (The program is actually written in scalafx, but I don't think that matters here because scalafx is just a wrapper of javaFX and calls all the javaFX methods.) Someone from the scalafx user group found out, that when I put in a wait time of 350ms (The animation time of the TitledPane is 300ms) then the call of 'edit' on the cell succeeds. He thought that the call fails, when the rendering of the content of the TitledPane is not complete. This is also true when I turn the animation for the TitledPane off. In this case, it is sufficient to wait for 50ms, which does not work when animation is on.
Anyway - I am concerned about just waiting 350ms and hoping that this will always work. Which brings me back to the question: How can I tell that the rendering inside the TitledPane (or the spreadsheetView?) is complete so that I can safely call my edit method on the spreadsheetView?
...ANSWER
Answered 2021-Apr-30 at 13:07Astonishingly, that doesn't seem to be supported.
The property that changes during the expand/collapse phase is the content's height: so a hack around might be to listen to it and start editing when fully expanded (which is a bit hacky in itself, could change due to layout constraints as well).
The example below simply initializes the fully expanded height after showing, listens to content's height property and starts editing when it reaches the fully expanded height.
The code:
QUESTION
I want to use a TableView
in scalafx to have a nice table in my GUI where the user can see and input data. There are some nice methods in the classes TableViewSelectionModel
and TableViewFocusModel
that i would like to use, like for example selectionMode
, selectedCells
and selectBelowCell
from TableViewSelectionModel
or focus(pos)
, focusedCell
and focusBelowCell
from TableViewFocusModel
.
I have the following example, that comes mainly from a youtube-video from Mark Lewis (who makes excelent learning videos for scala and scalafx by the way, but doesn't cover this topic):
...ANSWER
Answered 2021-Mar-26 at 16:02With the problem of wrong highlighting out of the way, the solution is simple. Just for reference, here is the above code modified with all the asked Options for TableView:
QUESTION
My goal is to have an MVC pattern in a simulation application where the controller knows there is a view (and interacts with it using an interface) but doesn't know how it is implemented:
...ANSWER
Answered 2020-Oct-05 at 13:04Well, you can design your application as abstract e.g.
QUESTION
I used sbt-assembly on a project where I have some java 14 jars, and my local machine has JDK 8 as the default JDK.
The sbt assembly
task was successful and produced a fat jar.
When I run it with JDK 8, I get the error:
...ANSWER
Answered 2020-Aug-13 at 19:29A JAR is just like a zip of classes, each class is the one that you can check with javap
to see which JDK version they need by looking at the value of the "major version" field; see this.
If you want to ensure the classes are compiled to a specific Java version, you can use the release
& target
scalac options.
Like this:
QUESTION
I'm playing with ScalaFX because I want to make an encrypted file app but, like the title said, I'm running in to problems. I want to avoid using brackets as I think they are ugly.
...ANSWER
Answered 2020-Jul-22 at 15:36One of the issues here is that List()
doesn't work the way you appear to think it does.
Firstly, the :+
operator does indeed append an element to the list (which is a slow operation, since the entire list must be copied each time; you should prefer prepending instead). However, this operator returns a new list containing the appended element, but since you don't store the result, it is thrown away. (Scala List
s are immutable elements, and cannot be modified, so List
operators return new List
instances instead. This is actually highly desirable for Scala's Functional Programming paradigm.)
Secondly, List
s are not observable. Even if you could modify lists by adding elements to it, there would be no way for topMenuBar.menus
, menuFile.items
or menuEdit.items
to know about the additions to their lists. So, all you're doing is copying empty lists to each element.
There are a few alternatives, one which involves initializing List
instances before assigning their contents to the GUI, and the other which uses an ObservableBuffer
instead of a List
. (If using an ObservableBuffer
, you would have to bind it to the associated property, using the ScalaFX <==
operator; there are examples in the ScalaFX demo models. For further background, ObservableBuffer
is the ScalaFX equivalent of JavaFX's ObservableList
.) I'd prefer the former, because observable elements should typically only be used if you need to dynamically modify them during your program's execution.
Here's the first approach, which populates the lists first, then assigns them to the associated GUI element:
QUESTION
I am following on from a previous question: link
- I am writing a standalone visualization package for a simulation package
- The simulation package is written by one of our team in Scala
What I want to do, is create a matplotlib like package for this simulation package. My envisioned end use would look something like matplotlib:
...ANSWER
Answered 2020-Jun-03 at 22:41Most JavaFX example code conflates the main
method with the Application
subclass, and in many cases even does the UI layout, etc., in the same class. There's not necessarily a reason to do this, and in the latter case it's not a particularly good design.
Assuming you separate concerns appropriately in your UI code, you might have a class like
QUESTION
I am using ScalaFX and trying to learn how it works. As an exerpiment (not what I will do in production) I want a method that gets the title of a window.
So here is my Graph.scala file:
...ANSWER
Answered 2020-May-31 at 20:06The problem here concerns JavaFX (and hence, ScalaFX) initialization.
Initializing JavaFX is a complex business. (Indeed, I only recently learned that it was even more complicated than I originally believed it to be. Refer to this recent answer here on StackOverflow for further background. Fortunately, your problem is a little easier to resolve.)
ScalaFX simplifies JavaFX initialization greatly, but requires that the JFXApp
trait be used as part of the definition of an object
.
JFXApp
contains a main
method, which must be the starting point of your application; it is this method that takes care of the complexities of initializing JavaFX for you.
In your example, you have your Driver
object extend scala.App
, and so it is App
's (and hence, Driver
's) main
method that becomes the starting point of your own application. This is fine for a regular command line interface (CLI) application, but it cannot be used with ScalaFX/JavaFX applications without a great deal of additional complexity.
In your code, JFXApp
's main
method never executes, because, as it is defined as a class member, it is not the main
method of a Scala object
, and so is not a candidate for automatic execution by the JVM. You do call it manually from your Graph.generateChart()
method, but that method itself is not called until after you try to get the title of the scene, hence the NPE as the stage has not yet been initialized.
What if you put the graph.generateChart(args)
call before the println(graph.getTitle())
statement? Will that fix it? Sadly, no.
Here's why...
JFXApp
also performs one other bit of magic: it executes the construction code for its object
(and for any other class
es extended by that object, but not for extended trait
s) on the JavaFX Application Thread (JAT). This is important: only code that executes on the JAT can interact directly with JavaFX (even if through ScalaFX). If you attempt to perform JavaFX operations on any other thread, including the application's main thread, then you will get exceptions.
(This magic relies on a deprecated Scala trait, scala.DelayedInit
, which has been removed from the libraries for Scala 3.0, aka Dotty, so a different mechanism will be required in the future. However, it's worth reading the documentation for that trait for further background.)
So, when Driver
's construction code calls graph.generateChart(args)
, it causes JavaFX to be initialized, starts the JAT, and executes Graph
's construction code upon it. However, by the time Driver
's constructor calls println(graph.getTitle())
, which is still executing on the main thread, there are two problems:
Graph
's construction code may, or may not, have been executed, as it is being executed on a different thread. (This problem is called a race condition, because there's a race between the main thread trying to callprintln(graph.getTitle())
, and the JAT trying to initialize thegraph
instance.) You may win the race on some occasions, but you're going to lose quite often, too.- You're trying to interact with JavaFX from the main thread, instead of from the JAT.
Here is the recommended approach for your application to work:
QUESTION
Yesterday I`ve asked how may I handle keyboard input (with ScalaFX) in a functional manner. Thanks to @alfilercio help I came up with something like this:
...ANSWER
Answered 2020-May-18 at 12:13Personally I would assume that all Listener
s and Handler
s are by definition impure objects from outside of our pure world, so if I wanted to keep things pure, I would make them send commands as values through some IO.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install scalafx
Snapshot releases are also regularly published on Sonatype Snapshots. To use a snapshot build you may need to add "Sonatype OSS Snapshots" resolver to you SBT configuration:. If you just want to download a recent snapshot build you can also use Travis CI build site https://travis-ci.org/scalafx/scalafx.
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page