Free scroll pane (JavaFX) - java

What pane can I use to add anchorpanes(setting y and z).
Initially it is of a certain size, and if it is too many anchorpanes to show, i`d like to add a scroller with which I can scroll down the pane to see more elements.
P.S.
sry for my bad english

This Question is very simple to answer. Just use a Scroll Pane and a Element to group your Anchor-Panes, for example :
ScrollPane with VBox as Grouping
Or you can also use Frameworks for this like :
http://www.jfoenix.com/
http://fxexperience.com/controlsfx/
When I remember correctly, they designed a Pane which is automatically placing nodes like a Gallery. These nodes get moved when necessary.

Related

placement of dynamically added buttons in javafx

I have dynamically created a bunch of buttons. I gave a fixed width to each of them. I want it to be added until space is available to its parents and when it overlaps with some other nodes, it will automatically go to the next line in order to avoid collision. I want it to be responsive at different screen sizes.
for(Data i:datas){
Button btn=new Button(i.getName());
anchorPane.getChildren().addAll(btn);
}
I want to arrange the buttons in a new line only when the buttons in the first line have covered its total width. How can I accomplish it? Any help is appreciated.
James_D provided a great resource—there's a built in layout for anything you need and FlowPane has what you want here.
Using your example, just swap out your AnchorPane for FlowPane:
FlowPane flowPane = new FlowPane();
for(Data i:datas){
Button btn=new Button(i.getName());
flowPane.getChildren().addAll(btn);
}
To make it responsive (i.e. expand and contract with the parent container/stage), bind the FlowPane's width and height to those of its parent:
flowPane.prefWidthProperty().bind(stage.widthProperty());
flowPane.prefHeightProperty().bind(stage.heightProperty());

JavaFX small collapsible pane?

I want a panel around two text fields that can be collapsed, similar to a TitledPane with no text. However the TitledPane uses too much vertical space so that it saves almost no space, as it reserves the space normally used for the title. Does JavaFX offer a really space-saving panel, lets say a rectangle with a triangle for collapsing?
There is no such ui control in JavaFx apparently. You must implement your own "collapsible pane" . It is possible to use TreeView but I think it can only hold text values as child elements.

Java Swing Custom Layout Issue

I'm having trouble organizing the contents of a JPanel. I've tried different layout managers but haven't gotten anything to work.
The JPanel contains 3 other JPanels and should look like this:
Does anyone know how I can achieve this layout?
Thanks in advance.
What you want is similar to a BorderLayout, but using one natively will cause the second pane to fill the bottom space (rather than the 3rd pane.)
However, you could use two in tandem to get this effect - The first BorderLayout pane would contain the second BorderLayout pane (in its centre) and panel 3 (on its east.)
In the second BorderLayout pane, you could then just set pane 1 to be the centre, and pane 2 to be the south.
Simplest, but not best solution, is to use null Layout Manager with manually set components bounds. It is called Absolute Positioning
Other approach is to use horizontal SplitPane with nested Vertical SplitPane: left one will contain vertical splitPane with Panel1 and Panel2, and right will be just Panel3.

JXMultiSplitPane going bonkers when I switch tabs

I'm using JXMultiSplitPane (from SwingX 1.6.2) to implement a three-pane horizontal interface. In the center pane is a JTabbedPane with two tabs: one with a JTextArea (in a JScrollPane, of course) used for entering Markdown code and the other a JEditorPane (again, in a scroll pane) for displaying a rendered HTML preview. When the user switches to the preview pane, the text in the editor is processed and displayed in the preview pane.
My problem is that if I enter text in the editor with long lines, and then switch to the preview, the center pane will expand. Sometimes it's just by a little bit, other times it'll take up more room than is actually on the screen. But if I move one of the resize handles manually, everything will snap back in place.
I've found only two ways to deal with this before it happens:
Manually resize one of the panes before entering any text.
Give the center pane a weight of 1 in the MultiSplitLayout model.
I can't use the second one since it will expand the center pane to take up almost the whole window by default.
Is there a way to fix this?
Update
After a little more testing, even technique (2) doesn't keep the size constant; switching between the two tabs changes the size of the center pane slightly.
I now believe that the problem is partly with the tabbed pane. The JTextArea and the JEditorPane do not have the same size and that JTabbedPane is resizing when I switch between them (since I'm resetting the JEditorPane text every time. This wouldn't be a problem except that JXMultiSplitPane will keep automatically resizing the center pane until the user forces a specific size by resizing manually.
So I should be able to fix the issue by making the size of the JTabbedPane fixed, but still able to be resized by the handle bars. Any tips on doing that?
The MultiSplitLayout is .. a LayoutManager, so you have to understand how it works (me too, not overly familiar with it myself :-)
The basic layout happens according to the component's prefSize, the weights are for distributing excess/missing space relative to the pref. By default, the dividers are "floating", that is they are positioned between the components as layouted by the basic mechanism. The moment a user touches a divider, dividers are "not-floating", comp sized to fit in-between the dividers. That's the reason for you not seeing the size-greed after moving the divider once. So one ways out is to
setup the JXMultiSplitPane as usual, add the components and realize the frame
fix the dividers after the manager has done its initial layout
String layout = "(ROW " +
"(LEAF name=selector weight=0.15)" +
"(LEAF name=center weight=0.7)" +
"(LEAF name=list weight=0.15)" +
")";
JXMultiSpitPane pane = new JXMulitSplitPane((MultiSplitLayout.parseModel(layout))
// add components and realize the frame
...
pane.getMultiSplitLayout().setFloatingDividers(false);
Alternatively, give more weight to the weights - force the layoutManager to use them for the layout itself (instead of only for the distribution of excess/missing space). A side-effect is that the prefSize of the comps might be set (by the layout, which is a no-no-never, but who's perfect ;-)
pane.getMulitSplitLayout().setLayoutByWeights(true);
Not sure which way I would prefer or if/how that could be made easier in the multisplit ..

how to generate this layout in java swing

I am wondering if anyone can help me with the generation of this layout:
I have wasted a lot of time.
What I want is:
1) The sizes of jButton1, jLabel1 and jLabel2 are the same as their original ones on resizing.
2) The sizes of jTextField1 and jTextField2 will automatically expand on resizing, but the total width of jTextField1+jLabel1 is the same as jTextField2+jLabel2.
3) The heights of JTree1 and JTree2 will automatically expand on resizing, and their widths are the same. They need to be placed in a JScrollPane so that there will be scrollbars when the trees get expanded.
Thanks a lot!
Look here:
http://download.oracle.com/javase/tutorial/uiswing/layout/visual.html
I would personally wrap the whole thing in a GridBagLayout for the flexibility it offers. Beyond that I often find it easier to put stuff inside GridLayouts or BoxLayouts and then put those in the GridBagLayout so that I don't have to deal with specific weights for every object.
It may take some experimentation.. I would start with a BorderLayout with "Top" and "Center"
"Top" only contains the button (You may need to find a container that makes it do what you want--you have to find something that presses it out to the right size). Center contains the rest.
In center you place something that divides evenly, I think a horizontal flow layout will do that. Might also use a splitter to drag the sizes if you want.
In each of the two sides of the flow layout (or whichever works). you add a BorderLayout with the label and text at the "top" and the "center" being left for the tree.
For the label and text field you might want to use ANOTHER BorderLayout and specify west for the button and center for the field.
Your components should then resize the way you want.
In summary, perhaps something like:
BorderLayout
top:
BorderLayout
bottom:
button (May need to be in another container to get the size right)
center:
Split pane or flow layout
left side (Same as right side):
BorderLayout
top:
BorderLayout
west:
label
center:
textbox
center:
JTree

Categories

Resources