Alternatives for paintComponent in javafx - javafx

I have a question but maybe it was an old question.
I saw a class that extends JPanel and an override function called paintComponent for updating panel.
I use javafx, so i want to know is there any alternative for paintComponent?
I want to update a scene in my game loop, or when i use setScene for my stage.
Thanks.

Related

How to use EMF Forms JavaFX Renderer

I want to create a custom control like this tutorial.
However, I do not want to use SWT, but JavaFX. But I do not know what class I have to inherit and how I can render my view in JavaFX.
In the SWT example, the class EmailControlRenderer extends from TextControlSWTRenderer. From which class would I have to inherit if I want to render an EObject in JavaFX?
From the EMF Forms documentation, it seems the JavaFX renderer is very much experimental at this point, so chances are you will not be able to do what you want to do. Consider sending the developers a mail.

Why is JavaFX singleton?

I would like to have a Java GUI library allowing something like this:
Window window1 = new Window();
window1.show();
Window window2 = new Window();
window2.show();
...
But a JavaFX window needs to be started within its own class extending Application and cannot be instantiated several times.
Why can a JavaFX window not be instanciated like other classes? Why is it called Application and not Window or Frame? Why does JavaFX breaks OOP? Why do we have to use singletons mixed with reflection? I want no magic, I want an OOP-behaving window object appearing on the screen.
But a JavaFX window needs to be started within its own class extending Application and cannot be instantiated several times.
This statement is wrong, there are restrictions on when you can invoke the constructor on the Window class, but they are not related to extending the Application class.
Why can a JavaFX window not be instanciated like other classes?
The constructor of the Window class is protected, so it can be "used only within the package and in sub-classes outside the package".
Instead, in your application, instantiate a class which is a sub-class of Window. The appropriate class to use is Stage. The constructors of Stage are public rather than protected like Window.
So, to show two stages (which are windows), you can write:
Stage stage1 = new Stage();
stage1.show();
Stage stage2 = new Stage();
stage2.show();
Why is it called Application and not Window or Frame?
An application is called Application because that what it represents. Within an application, you might have multiple Stages (which are instances of Windows), so it would not make sense to call an Application a Window. Anyway, an Application has a different purpose: It's main purpose is to implement the Application lifecycle interface and processing as described in the Application javadoc.
Why does JavaFX breaks OOP?
It doesn't. It uses a protected modifier on Window to enforce encapsulation, which is a key hiding technique of OOP. It provides subclasses of Windows via inheritance for different purposes such as Stages, which are your standard application windows, and PopupWindows, which are specialized window subsets helping with tasks such as creation of popup lists for context menus and combo boxes. It implements Separation of Concerns by differentiating between Application and Window functionality within separate class structures.
Your other questions and statements make no sense to me.

How to change Scenes in JavaFX without FXML

I'm trying to change Scenes in my Java FX program with resetting the Scene like
stage.setScene(new Scene(new StartupPane(stage),Toolkit.getDefaultToolkit().getScreenSize().getWidth(),Toolkit.getDefaultToolkit().getScreenSize().getHeight()));
Is this a proper way to do it?
I also have the problem that the CSS style doesn't apply on the new Scene after the change of a Scene. Is there a proper solution for it or do you recommend me to use FXML (actually I have no experience with FXML)?
Why do you want to change the scene? In general you can just change the root node of the scene and there is no need to change the scene itself.
Changing the scene can be done but this is independent of the question whether to use FXML or not.
thanks a lot, it's working fine now for me. I only found answers with changing the XML controller or something like that, therefore I asked for XML.
Thanks

how to bind scene with stage in javafx2

Actually I want to switch from one scene to another scene on particular event. So i can do that by setting scene of the stage without binding but i want to bind my stage with scene as soon as a flag changes my scene will change automatically....pls help
The JavaFX Demos and Samples Downloads contains an application called FXML-LoginDemo. It demonstrates how to change scenes in a stage. The important part happens in the method replaceSceneContent. As for automatically changing the stage when a flag in your application is updated, there are several ways to do that. I recommend using a PropertyChangeListener or using JavaFX withCDI and then using CDI events. I used the latter approach in my application and it works really well.

QWidget stays within parent QWidget

i'm quite new to Qt and i've a question.
I've got an application with multiple windows/QFrame. I'd like them to only exist within the mainwindow (it's also the parent gadget). When I move them, I want the to stay within the parent gadget.
Is is possible ?
If yes, how ?
I've been through the Qt doc and i've found nothing. I though maybe a simple option can do that. Or do I have to create a new Widget with customs mouse Event methods ?
Thx
If you want a Multiple Document Interface (MDI) GUI you can use the QMdiArea and QMdiSubWindow classes to implement this. Have a look at the detailed description section of QMdiArea for using it with a QMainWindow example, but it also works on any other widget as well.

Resources