Scaling an Address Form on Resize - java

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...

Related

Difference between "rigid area" and "strut" in Box

Could someone please explain the differences between
Box.createRigidArea(dimension)
and
Box.createHorizontalStrut(width)
Box.createVerticalStrut(height)
Is "Rigid area" a strut whose both dimensions can be user-specified, or is there more to it?
From the tutorial
http://docs.oracle.com/javase/tutorial/uiswing/layout/box.html
It looks like using struts as a filler may present problems when composing different BoxLayouts meanwhile rigid areas are more flexible since they allow you to specify both dimensions.
Specifically, a horizontal strut has effectively unlimited maximum height. So, if we put a horizontal strut in a horizontal box inside a vertical box, suddenly the horizontal box becomes taller. So, a horizontal strut also acts like vertical glue, I guess. Which, intuitively, is not what we expect from the idea of a "horizontal strut".

Dynamically resizing grid of buttons with Swing WYSIWYG editor?

I'm trying to code my first GUI-based game in Java and I chose the minesweeper. I'm quite a newbie in Java (though I can manage to program the logic part of the game so not "newbie" in the "I don't know what are classes" sense) and a complete freshman in Swing so I'd love if I could use the WYSIWYG editor (like the NetBeans one) for the graphics part rather than writing the layout by hand.
However, after playing with the editor, for my current understanding, I can only set a constant amounts of different containers with the Netbeans editor - I mean, I'd have to know in advance what dimensions do the board have to have. However, I'd like the board to resize dynamically so that when user may play on a 9x9 grid with 31 bombs just as well as on the 100x105 grid with 3 bombs. Can you create such dynamically resizing (of course not on-the-fly - I mean that user can decide what grid he wants to play on when he starts the game) grid of buttons with the WYSIWYG editor as well or such thing requires coding all of this by yourself from scratch?
write the layout by hand, this is job exactly for GridLayout
use JButton, better will be to use JToggleButton with Icon
Use proper setXxxIcon methods for JButton/ JToggleButton
uh - please do not do it with the GUI Editor. You will probably create way too much variable featured components.
Please code at least parts of that yourself - the buttons you probably use on the minesweeper field should easily be created in a loop. The button has a data field, which you can use for the status of the field (bomb, no bomb, hidden, marked, empty). So when you create the ONE Actionlistener for the buttons, you should be able to react on that there.
Your real question:
Yes, it depends much on the Layout you use. Avoid sizing and when you need to set Button Size, always refer to a base of 100%:
setButtonSize(){
int iWindowWidth = 437; // example, can be any value. Stands for 100%
button1.setWidth((int)(iWindowWidth * 0.2)); // 20%
button1.setWidth((int)(iWindowWidth * 0.3)); // 30%
button1.setWidth((int)(iWindowWidth * 0.05));// 5%
button1.setWidth((int)(iWindowWidth * 0.45));// 45%
}
That is also how I create tables with dynamic width defining the column width.

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.

Raw Java 2D implementation of a scrollbar

How would I go about writing my own scrollbar using standard Java 2D.
I really don't want to use swing, and I've already made up my own component parts for everything else such as buttons etc.
I'm not really looking for code, rather the math involved in the event changes and the drawing.
Why on earth would you want to write your own java GUI toolkit? You already have the choice of Swing and SWT, can you really do better than these two teams?
If you've already written the rest of the toolkit, I don't understand why the scrollbar would stump you. Without knowing anything about your event system, or how your custom components are structured, it's impossible to give much advise. I don't see this being particularly maths intensive - just maintain the height of the scrollable component, and the view it's in, and the scrollbar size should match the proportion of the component that is visible. The position of the scrollbar should match which part of the component is visible (this will have to be scaled). Specifically, what do you want to know?
Java is now open. I'd go look at the source for the Swing and/or SWT as they are already implemented. The math seems fairly straight forward. You have a Bar and a Container. To simplify we will only discuss length (the dimension in which the scrollbar moves). The container is of a certain length. The bar is of a length that is equal to or less than the container. It is useful to define the center and the two endpoints of the scrollbar. You can have the scrollbar start at 0 at the top and 1 at the bottom or 0 at the top and 100 at the bottom with the important part being defining your scrollbar in the same manner. Then you can check the endpoints for collision with the edge to stop the bar from moving. If the mouse is held down with the cursor over the coordinates inside the bar, the bar starts caring about where the cursor is and will paint the scrollbar and whatever the scrollbar is ultimately supposed to be affecting. So, you would take the page to be affected and map it to 0 and 1 * the scale in pixels of the scrollbar. Then you get to worry about the arrows at either end and how big of a jump each click is and dealing with mousedown events etc.etc. Use what is given don't reinvent the wheel.
While not Java2D, this straightforward code snippet might help:
http://processing.org/learning/topics/scrollbar.html

Categories

Resources