Home » Eclipse Projects » e(fx)clipse » Fitting a dialog to the size of its content
Fitting a dialog to the size of its content [message #1229535] |
Thu, 09 January 2014 11:53  |
Eclipse User |
|
|
|
I have a Dialog extension (an extension of org.eclipse.fx.ui.dialogs.Dialog) that contains various subpanels containing categories of search criteria a user may select from. Each panel is implemented as a TitledPane with the ability to collapse set to false. Initially I hardcoded the dialog size, but now I'd like to have the dialog size itself based upon its content. So, I tried the following:
...
import org.eclipse.fx.ui.dialogs.Dialog;
public class MessageSearchDialog extends Dialog {
public MessageSearchDialog(Window parent, String title) {
super(parent, title);
}
@Override
protected Node createDialogArea() {
BorderPane pane = new BorderPane();
pane.setPadding(new Insets(5));
Node searchPane = createSearchPane();
pane.setCenter(searchPane);
Bounds bounds = searchPane.getLayoutBounds();
pane.setPrefSize(bounds.getWidth(), bounds.getHeight());
// pane.setPrefSize(800, 450);
return pane;
}
...
}
Unfortunately, when the dialog is opened, it is sized as though all of the TitledPane panels were collapsed (i.e. only the title portion of the pane is visible, the content is not). I can resize the window with the mouse and everything then appears as the dialog window is enlarged. I also tried .getBoundsInParent(), but that made no difference.
Is there a way to make this work without having to hardcode the size?
|
|
|
Re: Fitting a dialog to the size of its content [message #1229589 is a reply to message #1229535] |
Thu, 09 January 2014 14:33   |
Eclipse User |
|
|
|
To get the preferred size you need to:
pane.impl_reapplyCSS(); // none public API
double w = pane.prefWidth(-1);
double h = pane.prefHeight(-1);
s.setWidth(w);
s.setHeight(h);
Tom
On 09.01.14 17:53, Joseph Gagnon wrote:
> I have a Dialog extension (an extension of
> org.eclipse.fx.ui.dialogs.Dialog) that contains various subpanels
> containing categories of search criteria a user may select from. Each
> panel is implemented as a TitledPane with the ability to collapse set to
> false. Initially I hardcoded the dialog size, but now I'd like to have
> the dialog size itself based upon its content. So, I tried the following:
>
>
> ..
> import org.eclipse.fx.ui.dialogs.Dialog;
>
> public class MessageSearchDialog extends Dialog {
>
> public MessageSearchDialog(Window parent, String title) {
> super(parent, title);
> }
>
> @Override
> protected Node createDialogArea() {
> BorderPane pane = new BorderPane();
> pane.setPadding(new Insets(5));
> Node searchPane = createSearchPane();
> pane.setCenter(searchPane);
> Bounds bounds = searchPane.getLayoutBounds();
> pane.setPrefSize(bounds.getWidth(), bounds.getHeight());
> // pane.setPrefSize(800, 450);
> return pane;
> }
>
> ...
> }
>
>
> Unfortunately, when the dialog is opened, it is sized as though all of
> the TitledPane panels were collapsed (i.e. only the title portion of the
> pane is visible, the content is not). I can resize the window with the
> mouse and everything then appears as the dialog window is enlarged. I
> also tried .getBoundsInParent(), but that made no difference.
>
> Is there a way to make this work without having to hardcode the size?
|
|
|
Re: Fitting a dialog to the size of its content [message #1229603 is a reply to message #1229589] |
Thu, 09 January 2014 15:01   |
Eclipse User |
|
|
|
Well I looked at the code and I don't understand why you need to do this.
If you set nothing the Dialog will open in its preferred size. Anyways
I've filed a bug and added 2 more methods:
* getInitialSize
* getInitialLocation
which are consulted before the Stage is opened. Please note these are
the stage values. You need to add the window decorations height!
Tom
> /*******************************************************************************
> * Copyright (c) 2014 __COMPANY/CONTRIBUTOR__ and others.
> * All rights reserved. This program and the accompanying materials
> * are made available under the terms of the Eclipse Public License v1.0
> * which accompanies this distribution, and is available at
> * http://www.eclipse.org/legal/epl-v10.html
> *
> * Contributors:
> * tomschindl<__EMAIL__> - initial API and implementation
> *******************************************************************************/
> package org.eclipse.fx.ui.dialogs;
>
> import javafx.application.Application;
> import javafx.event.ActionEvent;
> import javafx.event.EventHandler;
> import javafx.scene.Node;
> import javafx.scene.Scene;
> import javafx.scene.control.Button;
> import javafx.scene.control.TextField;
> import javafx.scene.layout.HBox;
> import javafx.stage.Stage;
>
> /**
> * @author tomschindl
> *
> */
> public class TestIt extends Application {
>
> /**
> * @param args
> */
> public static void main(String[] args) {
> Application.launch(args);
> }
>
> /* (non-Javadoc)
> * @see javafx.application.Application#start(javafx.stage.Stage)
> */
> @Override
> public void start(Stage primaryStage) throws Exception {
> Button b = new Button("Hello");
> b.setOnAction(new EventHandler<ActionEvent>() {
>
> @Override
> public void handle(ActionEvent event) {
> TitleAreaDialog d = new TitleAreaDialog(primaryStage,"Hello World","Hello World 2","Message",(String)null) {
>
> @Override
> protected Node createDialogContent() {
> HBox b = new HBox();
> b.getChildren().addAll(new TextField(),new TextField(),new TextField(),new TextField(),new TextField());
> return b;
> }
> };
> d.open();
> }
> });
> Scene s = new Scene(b);
> primaryStage.setScene(s);
> primaryStage.show();
> }
>
> }
On 09.01.14 20:33, Tom Schindl wrote:
> To get the preferred size you need to:
>
> pane.impl_reapplyCSS(); // none public API
> double w = pane.prefWidth(-1);
> double h = pane.prefHeight(-1);
> s.setWidth(w);
> s.setHeight(h);
>
> Tom
>
> On 09.01.14 17:53, Joseph Gagnon wrote:
>> I have a Dialog extension (an extension of
>> org.eclipse.fx.ui.dialogs.Dialog) that contains various subpanels
>> containing categories of search criteria a user may select from. Each
>> panel is implemented as a TitledPane with the ability to collapse set to
>> false. Initially I hardcoded the dialog size, but now I'd like to have
>> the dialog size itself based upon its content. So, I tried the following:
>>
>>
>> ..
>> import org.eclipse.fx.ui.dialogs.Dialog;
>>
>> public class MessageSearchDialog extends Dialog {
>>
>> public MessageSearchDialog(Window parent, String title) {
>> super(parent, title);
>> }
>>
>> @Override
>> protected Node createDialogArea() {
>> BorderPane pane = new BorderPane();
>> pane.setPadding(new Insets(5));
>> Node searchPane = createSearchPane();
>> pane.setCenter(searchPane);
>> Bounds bounds = searchPane.getLayoutBounds();
>> pane.setPrefSize(bounds.getWidth(), bounds.getHeight());
>> // pane.setPrefSize(800, 450);
>> return pane;
>> }
>>
>> ...
>> }
>>
>>
>> Unfortunately, when the dialog is opened, it is sized as though all of
>> the TitledPane panels were collapsed (i.e. only the title portion of the
>> pane is visible, the content is not). I can resize the window with the
>> mouse and everything then appears as the dialog window is enlarged. I
>> also tried .getBoundsInParent(), but that made no difference.
>>
>> Is there a way to make this work without having to hardcode the size?
>
|
|
|
Re: Fitting a dialog to the size of its content [message #1229605 is a reply to message #1229589] |
Thu, 09 January 2014 15:06   |
Eclipse User |
|
|
|
The correct none API method is "impl_processCSS(true);"
Tom
On 09.01.14 20:33, Tom Schindl wrote:
> To get the preferred size you need to:
>
> pane.impl_reapplyCSS(); // none public API
> double w = pane.prefWidth(-1);
> double h = pane.prefHeight(-1);
> s.setWidth(w);
> s.setHeight(h);
>
> Tom
>
> On 09.01.14 17:53, Joseph Gagnon wrote:
>> I have a Dialog extension (an extension of
>> org.eclipse.fx.ui.dialogs.Dialog) that contains various subpanels
>> containing categories of search criteria a user may select from. Each
>> panel is implemented as a TitledPane with the ability to collapse set to
>> false. Initially I hardcoded the dialog size, but now I'd like to have
>> the dialog size itself based upon its content. So, I tried the following:
>>
>>
>> ..
>> import org.eclipse.fx.ui.dialogs.Dialog;
>>
>> public class MessageSearchDialog extends Dialog {
>>
>> public MessageSearchDialog(Window parent, String title) {
>> super(parent, title);
>> }
>>
>> @Override
>> protected Node createDialogArea() {
>> BorderPane pane = new BorderPane();
>> pane.setPadding(new Insets(5));
>> Node searchPane = createSearchPane();
>> pane.setCenter(searchPane);
>> Bounds bounds = searchPane.getLayoutBounds();
>> pane.setPrefSize(bounds.getWidth(), bounds.getHeight());
>> // pane.setPrefSize(800, 450);
>> return pane;
>> }
>>
>> ...
>> }
>>
>>
>> Unfortunately, when the dialog is opened, it is sized as though all of
>> the TitledPane panels were collapsed (i.e. only the title portion of the
>> pane is visible, the content is not). I can resize the window with the
>> mouse and everything then appears as the dialog window is enlarged. I
>> also tried .getBoundsInParent(), but that made no difference.
>>
>> Is there a way to make this work without having to hardcode the size?
>
|
|
| |
Re: Fitting a dialog to the size of its content [message #1229996 is a reply to message #1229605] |
Fri, 10 January 2014 14:03   |
Eclipse User |
|
|
|
Now I have a different twist to the story. I'd like to have one of the search category panels (implemented as a TitledPane) be collapsible and have the dialog window resize itself to the current bounds of the content when the collapsible pane is expanded or collapsed.
I experimented a little with your suggestion:
pane.impl_processCSS(true); // none public API
double w = pane.prefWidth(-1);
double h = pane.prefHeight(-1);
s.setWidth(w);
s.setHeight(h);
but I cannot figure out how to affect the dialog size - I can't find accessor methods to set width or height. Your exmaple looks to be setting the width and height of the scene object, but I don't know how to get a handle to that in my dialog.
Another thing that I noticed when I did some tests was that it seems that the width and height returned from the impl_processCSS() call is the "old" size. Basically what I did was attach a ChangeListener to the expanded property of the TitledPane referred to earlier and printed out the width and height returned. The values printed always seemed to be the "old" size of the dialog, the reverse of what I need.
private Node createSearchPane() {
final GridPane pane = new GridPane();
...
code to set up other panels
...
TitledPane msgTypePane = new TitledPane("Type", createMsgTypePane());
msgTypePane.setCollapsible(true);
msgTypePane.setExpanded(false);
msgTypePane.expandedProperty().addListener(new ChangeListener<Boolean>() {
@Override
public void changed(ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) {
System.out.println(newValue);
pane.impl_processCSS(true);
double width = pane.prefWidth(-1);
double height = pane.prefHeight(-1);
System.out.println(width + "," + height);
}
});
pane.add(msgTypePane, 0, 3, 4, 1);
return pane;
}
So, with all of that said, what is a good way to dynamically resize the dialog window to handle the changes to the content bounds due to the collapse/expand of an item in the dialog?
|
|
| | | | | | | |
Goto Forum:
Current Time: Wed Jul 23 02:56:01 EDT 2025
Powered by FUDForum. Page generated in 0.09500 seconds
|