JavaFX scale components to fit parent without binding? - java

I am writing a JavaFX application which will have user definable number of components and I am looking for easy way to scale all groups so that no matter of the number everything will fit:
For example I have a Pane, than in the pane I might have > 0 number of groups of components. Each group consists of several TilePanes and each of those TilePanes can accommodate other components.
I would like to be able to create any number of groups (same structure) as described so that when the number of groups increases the components in the group will decrease size to fit in the Pane. The difficulty is that while the program runs it will be adding components in the TilePanes of each group and those components need to be resized properly to fit.
Currently I have the sizes hard coded, but as explained I need to create configurable number of groups (set on initializations).
Is there an easy way to get this done without having to bind all the elements to the size of their parent ? I thought TilePane will restrict the size of the elements inside, but as it turned out, even when I set the max size for the TilePanes, large components don't get resized.
Thanks

Related

How to set custom width for part sash container?

I'm new to Eclipse E4. I'm using part sash container. Is there a way to reduce the width of the left side? By default it container is separated by 50:50. I need that to be 30:70.
Sample screenshot. Here I need to reduce the width of left side. so that right side will have more space:
You do this by putting the relative sizes of the container's children in the Container Data field of each child.
So if you have two children for your part sash container the first child could have a Container Data value of '30' and the second child a value of '70'.
Note: It is better to use larger relative size values to get smoother resizing - so something like 3000 and 7000 in this case. It is just the relative values that matter as far as the sizing is concerned.

Grabbing Excess Space Equally

When using "Grab Excess Horizontal Space" on multiple SWT controls within the same space, the default behavior does not divide the space between them exactly equally. Some sort of behind-the-scenes calculation seems to be done to divide it "sort of" equally, but giving a higher ratio to larger controls.
In my example here, I have created a custom table-like control using grid layouts in which the user can add any number of rows, as well as any number of boxes (custom canvases) for each row individually. My intent is to have all boxes within a given row be of equal size - and by that virtue, all rows with an equal number of boxes will have equally-sized boxes, despite being separate. In my example, however, you can see that the one box that has label text within it grabs more space than those on the same row, due to the calculation believing that it "needs more" than the others.
What would be the best way to tackle this issue?
You can try to use makeColumnsEqualWidth from GridLayout.

Scaling an Address Form on Resize

My application has a form for filling in the names and addresses of a donor. Each donor gets a closable tab and each tab has an address form.
The problem is that the application runs in a regular application window and therefore gets scaled to all different sizes. If I make the width and height of the text fields static, they all stay in the upper left of the window on a big screen. If I make them dynamic, the form looks bad because of massive boxes for relatively small amounts of text (i.e. first name). If I space them out dynamically, I end up with large gaps in between the boxes.
What is the best way to deal with this issue? Is there a UI construct normally used for this (so far the only one I've seen used has been to put the form in a non-scalable modal dialog, which I can't do because of the tab-based UI).
Thanks
Just a suggestion- an easy way out, taken by lots of web designers *(I know your app is not browser-based):
Constrain the content to a fixed size (e.g. 800px), and center that box horizontally. If the user maximizes their window, they see the 800px content centered with large empty gaps to right and left.
IMHO, this is not the best, but it doesn't look as bad as if it were packed into the upper left.
This is a graphic design question, not so much about the technology...

Draw2D GridLayoutAlgorithm with constant node width?

We're integrating Draw2D/GEF into an application, and are encountering an issue with the standard layouts provided.
We have a collection (say 100) of elements that need to be displayed in a grid-like fashion. We implemented our view using a GraphViewer, and applied a GridLayoutAlgorithm.
This works almost as we'd like it to, but the one stipulation we haven't been able to meet is that each node must be of a constant, defined size. Say, 50x50 pixels. The current GridLayoutAlgorithm we're using resizes the nodes so that they all fit in the window. If our window is small, the 100 elements become minuscule. We would instead like them to fill the width, then wrap to multiple rows, with a vertical scrollbar.
For the life of me, I can't find a simple, straightforward way to accomplish this.
Kind of a bummer answer, but I just ended up writing my own subclass of a GridLayoutAlgorithm and did a bunch of the math by hand. Frustrating that this wasn't included out-of-the-box, but it works fine.

Java Swing Gridlayout: Accessing Specific Coordinate

I'm creating a Java swing GUI and I have formatted a JPanel to use a GridLayout. I need to access a specific "box" (i.e. specific coordinate) of the grid, but I cannot see a way to do so.
How can I do this?
You shouldn't depend on GUI code (the View) to give you information about program data (the model). The best solution would be to "know" which component is where from the start--maybe you should have a data structure (2D array?) that holds the components and is updated whenever something's added to the grid.
If you want a quick and very-dirty fix, though, you could start playing games with JPanel.getComponentAt(). This requires pixel coordinates, though, so you'd need to do some reverse-engineering to figure out how much space a given grid square takes up. The space between grid squares is given by your GridLayout object. This is not recommended whatsoever though. I'm just including it in the interest of completeness (and since it's a more literal response to your question).
In GridLayout, "The container is divided into equal-sized rectangles." You can add an empty, transparent component in places you want to appear empty, e.g. new JLabel(""). See also GridBagLayout and Using Layout Managers.

Categories

Resources