I am implementing a user interface using gxt. I have mainForm class with TabPanel.
TabPanel has few TabItems. On orderManagmentTabItem I have a ContentPanel.
TabPanel mainFormTab = new TabPanel ();
mainFormTab.setAutoHeight(true);
mainFormTab.setAutoWidth(true);
TabItem orderManagmentTabItem = new TabItem("TabItem 1");
orderManagmentTabItem.setAutoWidth(true);
orderManagmentTabItem.setAutoHeight(true);
OrderManagmentTabPanel orderManagmentTabPanel = new OrderManagmentTabPanel(); //contentpanel
orderManagmentTabItem.add(orderManagmentTabPanel);
TabItem warehouseManagmentTabItem = new TabItem("TabItem 2");
warehouseManagmentTabItem.setAutoWidth(true);
warehouseManagmentTabItem.setAutoHeight(true);
So I want to set Autozise to orderManagmentTabPanel, but can't do this. I write setAutoHeight(true) and setAutoWidth(true) in orderManagmentTabPanel class, but whet I run my app orderManagmentTabPanel is empty.
Than I tried to set autosize after creating OrderManagmentTabPanel copy
TabItem orderManagmentTabItem = new TabItem("TabItem 1");
orderManagmentTabItem.setAutoWidth(true);
orderManagmentTabItem.setAutoHeight(true);
OrderManagmentTabPanel orderManagmentTabPanel = new OrderManagmentTabPanel(); //contentpanel
orderManagmentTabPanel.setAutoWidth(true);
orderManagmentTabPanel.setAutoHeight(true);
orderManagmentTabItem.add(orderManagmentTabPanel);
But didn't help also
Also tried to implement TabItem class without ContenPanel and add it to mainFormTab, but also didn't work.
How can I make my TabItem to be autosized?
Thx
OK so I believe you mean (correct me if I am are wrong) you have a panel on a tab item and are trying to ensure it takes 100% of the space?
try setting a layout for example
orderManagmentTabItem.setLayout(new FillLayout()); //Sounds like what your after
Related
I'm not sure how to do this:
I have a variable that is passed threw an intent to my new activity.
This variable is a Number. That number received threw the intent will be different depending on the user.
So I want to dynamically write buttons or texViews depending on Number variable.
Example : Number = 4;
There is 4 buttons or textviews (with onclick listener each and text written has Button 1, Button 2, et. ).
Example Number = 10;
There is 10 buttons or textviews or etc. (with onclick listeners each).
Not sure how I can approach this problem
You can create new dynamic views something like that:
Button myButton = new Button(this);
myButton.setText("Push Me");
LinearLayout ll = (LinearLayout)findViewById(R.id.yourLinearLayoutId);
LayoutParams lp = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
// with addView method you say to your app when you want to add this view inside on your LinearLayout view
ll.addView(myButton, lp);
Using Vaadin Flow Java API I would like to emulate a Vaadin 8 Window feature: particularly I need to emulate Caption behaviour.
I mean a fixed top "Title" not scrollable as the real content of the Dialog. Anyone can tell me some Example I could learn from ?
Thanks in advance
This is the workaround I found.
public MainView() {
Button button = new Button("Click me",
event -> {
Dialog dialog = new Dialog();
HorizontalLayout horizontalLayout = new HorizontalLayout();
VerticalLayout verticalLayout = new VerticalLayout();
Div headerDiv = new Div();
Div bodyDiv = new Div();
bodyDiv.getElement().getStyle().set("overflow", "auto");
bodyDiv.getElement().getStyle().set("max-height", "420px"); // !!!
dialog.add(headerDiv, bodyDiv);
headerDiv.add(horizontalLayout);
bodyDiv.add(verticalLayout);
horizontalLayout.add(new Label("Hi there !"));
for (int i = 1; i <= 20; i++) {
verticalLayout.add(new TextField("TextField_" + i));
}
dialog.open();
});
add(button);
}
The trouble is that I have to fix max-height size to avoid scrolling of all the contained components. So I cannot take advantage from the auto-size behaviour of the Dialog Container. Also tried using setFlexGrow, but I did not reach the solution.
Any Hint ?
In Vaadin 10+ there is no component called Window, but there is component called Dialog. It does not have Title like Window, but otherwise it has similar baseline. I.e. it is popup. Based on your question you have found already that.
Dialog itself is component container, which means you can add components there. I would just create e.g two Divs (the simplest of the layout components in Vaadin 10). I would style the first one to have fixed height and place the Title there. And then I would apply component.getElement().getStyle().set("overflow", "auto") to the other one, which is the actual content body. The mentioned style will enable the scrollable feature. You could potentially use VerticalLayout / HorizontalLayout instead of Div as well depending what you need.
See also: https://vaadin.com/docs/v10/flow/migration/5-components.html
I want to add nodes into the TitledPane's header. The only way I found to do it is using setGraphic() method.
The problem of using that way is I cannot place them neatly. Here is what I get:
The Codes
TitledPane tpane = new TitledPane();
tpane.setContent(new Text("Content"));
tpane.setExpanded(false);
Button b = new Button("Delete");
BorderPane box = new BorderPane();
box.setLeft(new Text("1 "));
box.setCenter(new Text("Single Pane"));
box.setRight(b);
AnchorPane par = new AnchorPane(box);
tpane.setGraphic(par);
VBox vbox = new VBox();
vbox.getChildren().add(tpane);
The Goal
I want to put the Delete button to the right, that's why I am using Borderpane. So the BorderPane need to fill the entire of the TitledPane's header width minus the space for small triangle
How can it be done inside setGraphic() method? Or are there any better way to achieve it?
To fix your problem try setting the width of the BorderPane to the width of the scene minus the arrow like this.
TitledPane tpane = new TitledPane();
tpane.setContent(new Text("Content"));
tpane.setExpanded(false);
Button b = new Button("Delete");
BorderPane box = new BorderPane();
box.setLeft(new Text("1 "));
box.setCenter(new Text("Single Pane"));
box.setRight(b);
AnchorPane par = new AnchorPane(box);
tpane.setGraphic(par);
VBox vbox = new VBox();
vbox.getChildren().add(tpane);
box.setPrefWidth(scene.getWidth()-30);//You can adjust the number to fit your needs and change scene to whatever the name of your scene is
I hope this helped
Well, it seems that support for javafx users is not as massive as the mainstream framework.
After some tries by the suggestion from #Austin, I found the way to do what I want, and this is also give dynamic sizing.
box.prefWidthProperty().bind(scene.widthProperty().subtract(35));
TitledPane tpane = new TitledPane();
tpane.setContent(new Text("Content"));
tpane.setExpanded(false);
Button b = new Button("Delete");
BorderPane box = new BorderPane();
box.setLeft(new Text("1 "));
box.setCenter(new Text("Single Pane"));
box.setRight(b);
tpane.setGraphic(box);
box.prefWidthProperty().bind(scene.widthProperty().subtract(35));
VBox vbox = new VBox();
vbox.getChildren().add(tpane);
I have an application with two menu bars (application menus and administration menus) on the top row and a search box in between them. The first menu bar is left justified with the search box immediately following while the second menu is right justified. This leaves room for additional application menus without moving the administration menus.
I tried an HBox, but can't get the second menu right justfied.
I tried using an AnchorPane and anchoring the application menu to the left and the admin menu to the right. This works fine until you resize it. When the display gets too small to show both menus it starts truncating letters. I want it to wrap the second menu to the next line.
I tried using a FlowPane which works great for getting one to flow under the other when resized, but I can't get the second menu reliable right justified. I tried a trick of putting a listener on the parent width and calculating the hgap to use, but the first time this gets called, the menu bars have a size of 0 and so the hgap is too big for the actual menus. After I resize it once, that trick works beautifully.
Even better would be a menuBar that could flow automatically so that I didn't have to break it up to allow it to wrap around. But if that capability exists, I've been unable to find it.
AFAIK MenuBar does not support wrapping its Menus.
There can be different approaches to achieve the layout you want. One of them at the below.
To align the second admin flowPane to the right, use HBox.setHgrow for flowPane. To align menu bars in flowPane, use flow.setAlignment(Pos.TOP_RIGHT):
#Override
public void start(Stage primaryStage) {
final Menu menu01 = new Menu("App Menu 1");
final Menu menu02 = new Menu("App Menu 2");
final Menu menu1 = new Menu("Admin Menu 1");
final Menu menu2 = new Menu("Admin Menu 2");
final Menu menu3 = new Menu("Admin Menu 3");
MenuBar menuBar0 = new MenuBar();
menuBar0.getMenus().addAll(menu01, menu02);
menuBar0.setMinWidth(220); // do not shrink
MenuBar menuBar1 = new MenuBar();
menuBar1.getMenus().addAll(menu1);
MenuBar menuBar2 = new MenuBar();
menuBar2.getMenus().addAll(menu2);
MenuBar menuBar3 = new MenuBar();
menuBar3.getMenus().addAll(menu3);
FlowPane flow = new FlowPane(Orientation.HORIZONTAL);
// flow.setStyle("-fx-background-color: gray; -fx-border-color: red"); // visual debug
flow.setAlignment(Pos.TOP_RIGHT);
flow.setHgap(0);
flow.getChildren().addAll(menuBar1, menuBar2, menuBar3);
TextField searchField = new TextField();
searchField.setPromptText("Search here..");
// make it unresizable
searchField.setMinWidth(200);
searchField.setMaxWidth(200);
HBox mainBox = new HBox(5);
mainBox.setAlignment(Pos.CENTER_LEFT);
HBox.setHgrow(flow, Priority.ALWAYS);
mainBox.getChildren().addAll(menuBar0, searchField, flow);
mainBox.setStyle("-fx-background-color: lightgray;");
VBox vBox = new VBox(0);
vBox.getChildren().addAll(mainBox, new Button("Demo"));
Scene scene = new Scene(vBox);
primaryStage.setScene(scene);
primaryStage.show();
}
First of all, I'm a long time Java/Swing developer. I recently installed JavaFX 2.2 to play around with.
I'm creating a fairly simple app, whose main window has a toolbar on top and content in the rest of the window. The obvious way to accomplish this is to use a BorderPane, and stick a ToolBar into the top section. So far, so good. However, I would like some of the controls in the toolbar to be at the left edge of the window, and some at the right edge. I can find no way to do this. I can put an invisible spacer object into the toolbar, but I only know how to give it a fixed width; it doesn't resize when the window is resized.
So I thought that instead of using a ToolBar object, I'll just use an HBox; it should be equivalent to a horizontally-oriented Swing Box object, right? And the Swing Box class has a createHorizontalGlue() method that inserts an auto-sizing spacer. Well, I can't find an equivalent in the JavaFX HBox class. Is there no simple way to do this?
I figured out how to do it using an HBox instead of a ToolBar to hold the controls; the key is the HBox.setHgrow() method, which allows you to set a spacer object to grow to fill the available space. I still don't know if it's possible to do this with an actual ToolBar instance.
/**
* Creates and populates the Node that serves as the window toolbar.
*
* #return a newly constructed and populated toolbar component
*/
private Node makeToolbar() {
// Auto-sizing spacer
Region spacer = new Region();
HBox.setHgrow(spacer, Priority.ALWAYS);
// Horizontal box containing toolbar controls
HBox box = new HBox();
box.setPadding(new Insets(8));
box.setAlignment(Pos.CENTER);
box.getChildren().addAll(openButton, spacer, resizeSlider);
// Colored background panel with drop shadow
Pane bgRect = new Pane();
bgRect.setStyle("-fx-background-color: #e0e0e0;");
bgRect.setEffect(DropShadowBuilder.create().width(1).build());
// StackPane to hold box and rectangle
StackPane stack = new StackPane();
stack.getChildren().addAll(bgRect, box);
return stack;
}
i do it this way:
private Node makeFooter(Node left, Node right) {
ToolBar footer = new ToolBar();
Region spacer = new Region();
HBox.setHgrow(spacer, Priority.ALWAYS);
spacer.setMinWidth(Region.USE_PREF_SIZE);
footer.getItems().addAll(left, spacer, right);
return footer;
}
hope i could help someone