Child window with maximize and close buttons - javafx-2

Still working on learning here ... I'm trying to make an application window (stage) into which I can call child windows. The parent naturally comes with minimize, maximize and close (x) buttons, but when I add a child window I can't move or resize the child, and it does not have the standard three buttons.
Here's code I've been toying with:
// Stage ventasStage = new Stage(); // originally the child was stand alone and had the standard 3 buttons
AnchorPane ventas = (AnchorPane) FXMLLoader.load(Punto_de_Venta.class.getResource("VentasGUI.fxml"));
// Scene ventasScene = new Scene(ventas); //"stage" and "scene" removed to add "getChildren"
home.getChildren().add(ventas);
The getChildren gets my new window to be part of the parent scene, but I cannot get the 3 standard buttons. I assume the buttons are added to a Stage and NOT to an AnchorPane (which is what getChildren is getting here) but getChildren can't be used with a Stage, right? So how do I make a parent with interchangeable children where each child is moveable, resizable and has the standard three buttons (minimize, maximize and close)?

Three buttons correspond to a standart Window (it is provided by OS), and it is Stage. Scene - is an object, which corresponds to scene graph and is a propeerty of stage. So use stage.setScene(..) to set Scene to Stage. Stene has a root node (usually, some kind of layout). And it seems for me, that you should use Scene.setRoot(...) method.
BTW, about Stage: you can use stage.init...() to use different decoration schemas, and different types of modality.

Related

How do you pass data into a chosen scene

Assume we have a main menu with multiple buttons, and we have a text file which contains data behind button 1, button 2, etc.... The text data is loaded into an array of dictionaries.
We are loading a scene like this:
# Global singleton provides a data set, i.e.
var mydata = [{...}, { ... }, etc...]
# On the main menu scene we have buttons
func _on_Button1_pressed():
get_tree().change_scene("res://DataList.tscn")
newscene???.send_data(mydata[0]) # ????
How do I pass the preloaded dictionary object associated with Button1 into the scene that is about to appear?
I understand that change_scene() is "deferred" so we cant just straight away call a "setter" function for this scene, or can we? I am still learning godot so I am a bit lost as to know how to do this
Note that I am expecting to "build up" and "rebuild" the new scene when the user presses the button, and "teardown" when a user exits the scene.
# Global singleton provides a data set, i.e.
If you already have an autoload (singleton), I would put there the information you want to give the other scene, and have the other scene read it.
I understand that change_scene() is "deferred" so we cant just straight away call a "setter" function for this scene, or can we?
Correct, you can't. For the instant where the new scene is loaded the current one is already unloaded, so it can't really call a method on the new one.
Unless you take control of the process. See Change scenes manually.

MFC non-modal dialog front but not topmost

Recently I would like to bring a dialog in front of it's father window(always do, no matter its father window gets focus or not) but not topmost. In other words, I only want it cover its father window but not other applications' window.
I've tried:
// this covers other windows
SetWindowPos(&wndTopMost, rectPos.left, rectPos.top, width, height, SWP_SHOWWINDOW);
// this doesn't work
SetWindowPos(&GetParentFrame()->wndTop, rectPos.left, rectPos.top, width, height, SWP_SHOWWINDOW);
Any ideas?
Xiangguan Zheng, in your original post you stated:
I only want it cover its father window but not other applications' window.
Later in your comment you mentioned:
I want do edit the father dialog by clicking the buttons on the child dialog.
These are two completely different requirements.
If you want a second dialog to be contained in the parent dialog area, you can achieve this by setting WS_CHILD style to the second dialog and calling Create. this will show the child dialog over the top of the parent and keep it within the parent area.
to fulfill the second requirement, you will have to pass the pointer to the parent dialog as the second parameter in Create call, or pass it when the child dialog is instantiated. Either way, you will have to save that pointer in the child dialog and use it to either call the public function exposed by the parent or use the pointer to send/post messaged to the parent.

QT5: What is the Significance of a Layout's Parent?

I am attempting to write my first program using Qt5. I found a tutorial (zetcode.com/gui/qt5) with a number of examples, which all used dynamic layout creation. I'm trying to create a nested layout configuration, but I'm having a problem with specifying the parent parameter of the layout constructor. When I use the main window as the parent for the main layout and its sub-layouts, I get an error message, apparently telling me that QWidget can have only one QLayout. The window looks OK, but I haven't implemented all my functionality yet (slots and other code), so I don't know what, if anything, is broken. If I omit the parent parameter from the sub-layouts, I get no error messages and the window looks OK as well, but again I'm wondering whether this would affect my subsequent code additions.
Can anyone explain to me the significance of a layout's parent? I've noted that specification of the parent window in the layout's constructor is apparently not sufficient, because all of the examples I've seen call setLayout() at the end of the window's constructor. In particular, will my omission of a parent ever cause problems?
The "rules" are that there can be at most one top level layout on a given widget, and that widgets can be only children of other widgets, not of layouts. So what happens is that:
when you set a layout on a widget, the widget will take ownership of that layout;
when you add widgets on a layout, these widgets will be reparented to the widget the layout is/gets installed upon;
when you add a layout inside another layout, the inner layout becomes a child of the outer layout.
What you're probably seeing is a side-effect of creating a layout with a widget as parent, as in
QLayout *layout = new SomeLayout(widget);
This will try to install the layout on widget, and fail in case there's already one. The good news is, you can pretty much ignore passing parents around and rely on the system to do "the right thing". For instance:
MyWidget::MyWidget(QWidget *parent)
: QWidget(parent)
{
QHBoxLayout *mainLayout = new QHBoxLayout; // top level layout
QVBoxLayout *subLayout1 = new QVBoxLayout; // sub layout 1 stuff
QPushButton *button = new QPushButton("button");
subLayout1->addWidget(button);
// create more widgets...
mainLayout->addLayout(subLayout1);
QVBoxLayout *subLayout2 = new QVBoxLayout; // sub layout 2 stuff
QLineEdit *edit = new QLineEdit;
subLayout2->addWidget(edit);
mainLayout->addLayout(subLayout2);
setLayout(mainLayout);
}
This will correctly create a layout hierarchy and a parent/child relation so that nothing will get leaked.

onDraw called twice when View added dynamically by addView method

I want to add a new View to a Layout dynamically by layout.addView(view) method. The new View is not supposed to be visible, but I want it's Display List to be created so it doesn't have to redraw (call onDraw method) itself when I decide to show it (by animation, for example fade in).
I run this code:
customView = new CustomView(this.getContext());
customView .setAlpha(0.0f);
this.addView(customView ); // 'this' is RelativeLayout instance in this case
onDraw method gets called for customView and everything is fine. However, when I change anything in my layout (push a button, scroll, anything that invalidates layout), the onDraw method for my customView is called second time. After that, it isn't called any more if I don't invalidate my customView (correct behaviour).
I don't know why Android behaves this way. I want it to create customView, call onDraw, create a Display List for it, and not call onDraw any more until I invalidate my view. To sum up, onDraw is supposed to be called once.
And it has nothing to do with initial invisibility of customView, if alpha is set to 0.5f, behaviour is the same.
My question is, how to make Android call onDraw only once?
And if Android really has to call onDraw twice, then what should I do to enforce it to do it in some code right after this.addView(view); without setting up any timers because THAT would be totally ugly.
The behavior you are describing is ok and is a part of the android framework for view object -
Drawing
Drawing is handled by walking the tree and rendering each view that
intersects the invalid region. Because the tree is traversed in-order,
this means that parents will draw before (i.e., behind) their
children, with siblings drawn in the order they appear in the tree. If
you set a background drawable for a View, then the View will draw it
for you before calling back to its onDraw() method. Note that the
framework will not draw views that are not in the invalid region. To
force a view to draw, call invalidate()
(Taken from the official google android API docs).
Meaning your custom view is contained by the same view that contains the button\scrollbar etc. If you don't want it to be rendered everytime the onDraw method is called for the subtree your view resides in you can set the view's boolean flag to false - use setWillNotDraw() to do that. (you should place it on the activity's onCreate in order to render the view set this flag to false (which is also the default) and use invalidate() whenever you want to render the view).You can read the official google docs for further information.

JavaFX – exclude/include parent and all its children from layout dynamically

Background/Context:
I have a HBox as a parent and many child Nodes (Buttons, TextFields, Labels…). The HBox is a child of other container (BorderPane/VBox/Grid)
My questions:
How do I dynamically remove/exclude the parent (HBox) and all its children from layout?
I am looking for some three-state property on Node (like in Microsoft WPF):
Visible – visible and participate in layout
Collapsed – is not visible and do not participate in layout (applies to its children as well)
Hidden – is not visible but participate in layout
http://msdn.microsoft.com/en-us/library/ms590101.aspx
What options does JavaFX offer?
My solutions so far:
hBox.setManaged(false);
this work only for HBox, its children are still present
root.getChildren().remove(hBoxTop);
root.getChildren().add(hBoxTop);
Well, this looks like it could work.., but for example in case of root being BorderPane, once I remove/add and remove the HBox, the space after it remains unused. I already tried requestLayout() but id does not force thr rrot to fill it. Am I missing something? Is it correct approach to this problem?
Edited:
Well, I got this working.
Dynamically removing and adding for this specific case can be achieved by:
Remove:
root.setTop(null);
Add:
root.setTop(hBoxTop);
When I did not call setTop(null) on removal, BorderPane still reserved space for HBox (even after removal from its children).
IMHO: it is not very good model as it is parent-container specific. For example if I change, BorderPane to VBox a I had to change these methods as well. For VBox, remove/add on children collection works but I need to remember index so that HBox appears at same place after calling add.
Using root.setTop(null) is not a good idea because as you say it's specific to BorderPane.
I think the best solution is to use:
root.getChildren().remove(yourPane);
And use layout methods to place your other childrens as you want.
But maybe you should not use a BorderPane in the first place with the behaviors you want in your application.
Notice you can also do root.getChildren().clear() to remove all component and add it again to your layout but differently.

Resources