Tips on using SpringLayout? [message #1798437] |
Mon, 19 November 2018 05:22 |
Patrick Moran Messages: 141 Registered: March 2018 |
Senior Member |
|
|
I may be overlooking some website that has hints on using SpringLayout. It seems to do many things behind the scenes. Using the visual interface, it is difficult to sometimes impossible to get two ends of a spring connected to the same component. Trying to look at the code and make intelligent choices in rewriting the machine-generated stuff is difficult. For one thing, I made a simple vertical stack of five JTextAreas, and eyeballing each one to get the same dimensions proved a little tricky. I tried writing down a block of code, changing the height or width of a JTextArea in the visual interface, and then went to look at the block of code again. However, sometimes the whole thing had been rewritten, losing a couple of lines of code. Probably they weren't needed, but I was surprised to find the computer doing so much engineering.
I then tried to adjust them manually, and I got four out of five the way I wanted them, but there was one that would not permit its height to be nudged up the height of the letter "e." It was too short or too tall, and a big gap between the two. The others were not difficult to change.
I'm beginning to get the feel of this thing, but doing so seems more like computer art than computer science.
The first JTextArea in the group was indented by one space. I tried over and over again to make it look like the other four, but there appeared to be some restriction regarding what the first one in a stack of several had to look like.
Sometimes putting down a JTextArea on the screen will result in a collapsed something-or-other that looks like ||. Other times there will be the area where you can type in the name of the individual JTextArea, but no space for content around it.
Having gotten a stack of JTextAreas looking about as close to the desired as I figure I will ever manage, I realized that I would need to move the whole stack down on the screen if I were to really use it for the purpose I had in mind. But it appears that one can only move one component at a time and then only by click-and-drag. Arrow keys don't usually work. At least that is what I have experienced. I have yet to see anything more than a description of what SpringLayouts are, and hardly anything about how to use them skillfully.
Thanks for references to any more-than-basic tutorials.
|
|
|
|
|
Re: Tips on using SpringLayout? [message #1798694 is a reply to message #1798605] |
Thu, 22 November 2018 23:11 |
Patrick Moran Messages: 141 Registered: March 2018 |
Senior Member |
|
|
With some further work I have to ask why Eclipse has not provided instructions for using the GUI.. I suppose that some might decide just to code directly and ignore the visual interface. However, the visual interface has its benefits too.
The most useful thing I have learned is to be very careful of the "hook up lines" that the visual interface provides. If you intend to have a JTextField stay at a certain portion distance from the top and the left side, you may confidently put that element where you want it. However, the software might position it with regard to a button or label that happens to be somewhere above it, somewhere to the right side, or whatever. I haven't figured out how it is decided. It may be necessary to go into the source code and change things there to get what you will want in the long run. (If you leave it to the software to decide things and you have a stack of five JTFields,. they might all end up being defined in relationship to different software furniture scattered around the scene. In operation, that might turn out to be a bad idea. Expanding the window might result in one line of text being drawn to the left, one to the right,. one toward the upper edge, and so forth..
The second, and more devious tricky behavior is that when you try to put some component somewhere on the screen and the software does not want you to put it there, it may deliver it to the upper left corner of the window, or it might put it somewhere beyond the scope of your on-screen window.The only hint you will have that something has gone perversely wrong will be a thin dotted line heading off-screen to beyond one or another of its four edges. At first I. thought these extra buttons , labels, etc., could be deleted at my leisure later one. The trouble is that the software will sometimes calculate the location of the next component you draw on screen with regard to these far-remote and unseen software entities. So if you try to draw something on screen, and it disappears by folding in on itself or just disappears, go to your source code, find it'll and delete it there.
Placing many components on screen successfully seems to depend when drawing something like a JTextArea of seeing both a vertical and a horizontal midline appearing in the rectangles that represents the location where the component will occur.
When something like a JTextArea has been drawn on screen, you will see a couple of tiny choice buttons near the upper right corner of the rectangle. The results will not appear In the source code, but "set left alignment," "make resizable," etc. have consequences. The "make resizable" is obvious in intent and it usually seems to work. The alignment notations don't make sense to me yet.
If you want to get, e.g., a JTextArea to follow along with the right border, but it has set itself tp follow a label or whatever elsewhere on the screen, you can sometimes achieve the desired results by extending the JTextArea almost up to the boundary line for the right border. The little gray line that has been reaching upward toward a label or whatever will suddenly switch to connecting to the desired boundary line.
There are many weird effects. Sometimes adjusting a box of one sort or another will make it suddenly expand to cover mostof the svcreen . Earn that happens I usually need to delete the bloated box and make a new one from scratch..
Somebody must have put lots of time to make this part of Eclipse. It's too bad they didn't write down how tp operate it.
Some of the details about "alignment" are found here:
https://docs.oracle.com/javase/8/javafx/layout-tutorial/size_align.htm#JFXLY133
[Updated on: Fri, 23 November 2018 01:55] Report message to a moderator
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.05719 seconds