Run code on start with javaFX 2 - javafx

I would like to know how I can run code with the start of JavaFX 2 applications.
For example the Hello World application in Netbeans. How can I set elements invisible on start?
I use JavaFx with FXML and SceneBuilder.
With java I could just use "edit code" in Netbeans to put my code in and it would run on start.

With fxml you can attach a controller whose initialize method is invoked when the document is loaded (this would be the preferred way for me to initialize fxml based UIs in code).
JavaFX applications have a start method for processing initializing the GUI on startup.
In your fxml you can set the visibility property on a Node to define it's initial visible state.
You can create a CSS stylesheet and in that setup a selector which selects your node and does initial styling on it such as making it invisible.
FXML also allows you to embed scripting languages in the fxml document or external files which can be used to initialize the GUI and act on events.

Related

QT designer implementation error

Actually i activated the Qt creator from terminal ex: in Linux sudo Qt-creator.sh. so qt application opens.when i tried to design the UI by drag and dropping the buttons , widgets to form a type of UI.when i run the application , it just show the blank widget. the designed part done in UI is not implemented. so whatever changes done in UI designer, is not displaying when i run application. i don't no where is the issue. is it because of activating the qt from terminal.
the reason for activating qt creator from terminal because, i need to cross compile the binary code for Arm-Cortex controller. so i need to follow the steps for setting compiler for arm-cortex in qt application.however the cross compilation works. but if any changes done on qt designer, when i run the application , i cant able to see the changes in UI output window.
Let me start by providing some background.
The Qt library allows you to create graphical user interfaces (GUI) using two alternative methods:
QWidgets
Qt Quick
QWidgets uses a set of widgets written in C++ that you can either create and layout yourself using explicit C++ code, i.e. manually, or use Qt Designer to edit the interface of your applicaiton in a WYSWIG style, producing a .ui. file that you use in a certain way later on.
Qt Quick uses a declarative approach to creation of the user interfaces, with a special markup language similar to HMTL. We're not discussing it here as it's not the approach that you're using.
Now let's take a closer look at how Qt Designer works in conjunction with .ui. files, given that our application is written in C+.
Once you launch Qt Designer and edit a form, then save it, a .ui. file is produced. It's an XML file containing an hierarchical description of the UI you've created. However, to be able to use that form as the GUI of your application, additional steps are required. You need to "tell" the application to use this .ui. file. This is done as follows. A special executable, the UI compiler uic, is invoked (automatically via qmake or cmake) to process the .ui file, and generate C++ code in form of a header file. You then include the header file in the file that includes your application code, and use one of the three available methods to create the UI of your application using the generated code.
The simplest method is shown below.
class MyForm : public QWidget
{
Q_OBJECT
public:
MyForm(QWidget *parent = 0);
private:
Ui::MyForm ui;
};
The ui member object is an object of the class generated by uic - the UI compiler mentioned above. The class contains code for creating the user interface, organizing it into a layout, and managing it throughout the application lifetime.
Then, in the .cpp file, we have the constructor:
MyForm::MyForm(QWidget *parent)
: QWidget(parent)
{
ui.setupUi(this);
}
The important call here is ui.setupUi(this). This creates the UI elements, applies the layout, and sets the layout on the widget provided as the argument to this call. Remember, our class inherits from QWidget.
The other approaches include inheriting from the generated class and dynamically loading the .ui file, omitting the compilation by uic, using the QUiLoader class. Please consult http://doc.qt.io/qt-5/designer-using-a-ui-file.html for further reference.
As far as starting Qt Designer from terminal, it has no effect on the problem. Moreover, starting a GUI application as root is highly discouraged on Linux, as it poses a major security issue.

Set value of a file input in JavaFX web view via java

I have a WebView node in my JavaFX and the page loaded in it has a <input type=file>. I want to set this input's value to a file on disk. I know this is not possible by injecting javascript into the web view. But I'm wondering if I can get access to JavaFX internals in how these input fields are handled and set the value through there. There appears to be no mention of file input controls' handling in the docs so I'm lost on this.
When I click on the file input. JavaFX gives me a native file selector. So, I'm expecting there's some form of handler that is invoked when clicking on a file input, that asks the user to select a file and then fills the file input with this value. That's what I want to do.
I tried just getting the element and setting it's value, but of course, it didn't work.
webEngine.getDocument().getElementById("FileInput")
.setNodeValue("C:\\attachment.pdf");
This piece of code does nothing. No error, no result either.
So, any ideas?
JavaFX internally uses WebKit for the WebView node, thus it have the same security restrictions. It's not possible to set the value of <input type="file"/> programmatically, neither over JavaScript or Java.
I suggest you to use FileChooser without using the WebView node. What the WebView node shows is a select button, which calls a FileChooser, and a label with the selected file name. This can be easily implemented in Java source code using JavaFX.

QFileDialog in a non-QT app

I have an app that uses a 3rd party GUI framework, but I want to open files with using QFileDialog. I'm thinking of instantiating a subclass of QWidget that is invisible and serves the purpose of serving up the dialog.
Is there a better way to do this?
I don't see any need for an invisible widget, since the file dialog doesn't require a a parent widget in order to be shown up.
Since the dialog needs to have a Qt event loop running, you will need to either show the dialog modally using exec(), or using one of the static functions like getOpenFileName.
To use any of the widget classes, including the file dialog, you need to have an instance of QApplication, although that instance doesn't have to have its exec() method called.

Swiz framework with AIR - Using ViewAdded/ViewRemoved on child windows?

I'm trying to implement a popup window (NativeWindowType.UTILITY) in an AIR 2.7 application that uses Swiz for dependency injection.
I have followed the Swiz guidelines that I've been able to find, and implemented ISwizAware on the class that creates the window, and I am calling _swiz.registerWindow() before opening the window, and dependency injection works fine on the window itself after this.
However, the problem I am running into is that I have a child view within that window, and I have a mediator that uses the [ViewAdded] and [ViewRemoved] tags. Neither the view added nor view removed functions are triggering. I'm thinking the issue is either:
The child view is not correctly registering with Swiz.
The swiz instance doesn't know about the beans (I have tried manually adding the bean however, which didn't have any effect).
The ViewAdded and ViewRemoved metadata tags simply aren't working because each NativeWindow object has its own stage instance.
Anyone know more about this?
Popups are a special case since they don't get added under the same display tree as your application. Under Stage (the main wrapper for Flash Player), you'll have Application where your code resides for Swiz, but Popup is in a separate layer above Application. Since they're siblings, Swiz cannot listen in for when the popup is being added to the Stage.
The way around this is to either set the properties of the popup manually (which is normally the easiest way) or manually add the popup to Swiz's awareness. For this you'll have to look at the documentation since I haven't touched Swiz in a long time.

Dynamically changing mxml for UI description and state transition logic

I want to use Adobe mxml to create a swf. However, the mxml gets compiled to swf itself and is not available after creating the swf. I want to add states with UI components without compiling it every-time. Is it possible with mxml? If not, what other design approaches can I take?
The very nature of MXML and ActionScript and the Flash Platform is that you must recompile the app every time you want to make change. What you request is not possible.
There are a lot of things you can do--with ActionScript and MXML--to change the state of a component at run time based on some parameters.
As one example, when you click the down arrow button of a ComboBox the drop down will open. This is, essentially, a run time state change. There is no reason you can't perform the similar functionality with your own custom components.

Resources