This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 69823 - [50cat] Space Around Component forced to Default
Summary: [50cat] Space Around Component forced to Default
Status: NEW
Alias: None
Product: guibuilder
Classification: Unclassified
Component: Code (show other bugs)
Version: 5.x
Hardware: PC Linux
: P3 blocker with 1 vote (vote)
Assignee: issues@guibuilder
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-12-03 18:06 UTC by gugrim
Modified: 2008-03-10 15:06 UTC (History)
0 users

See Also:
Issue Type: ENHANCEMENT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description gugrim 2005-12-03 18:06:34 UTC
[ BUILD # : 200512011936 ]
[ JDK VERSION : 1.5.0_05 ]

When using Free Design layout with components that provide their own spacing, I have to change the
"Space Around Component" to remove the extra spacing added by the form editor. This doesn't work though:

I can change the Top spacing from Default to 0 but it is changed back to Default whenever I move the
component or cause it to be moved by moving another.

The Left and Right spacings can't be changed at all. They revert to Default immediatelly.

Since there is no way to set the Default value, this layout becomes unusable when using
such components. All the beans in our class library has built in spacing borders.

There should be a way to set the Default spacing. The first node inside a container node is usually
a layout node, where you can set properties. For some reason this is missing when Free Layout (i e
GroupLayout) is used.

I chose prio P2 although the bug writing guidelines advices me to use P1 ("Product feature
(identifiable part of functionality) does not work, no workaround exists"). Although I can't
find any workaround, it seems to be a serious problem only when you use beans with build in spacing.
Comment 1 Tomas Pavek 2005-12-05 17:41:04 UTC
There might be some case when setting the space to 0 does not work (due to a
bug), but it does not seem to be a general defect. I've just tried to change the
gap to 0 between several components and it worked. Could you provide/describe an
example that does not work for you?

The only case when the gap can't be changed is when it would require to change
the size of the whole form; if you have a resizing component in the layout you
should not have a problem though. Note you may also attach components directly
to container borders to avoid the border gaps completely.
Comment 2 gugrim 2005-12-05 18:02:49 UTC
Perhaps I happened to run into the bug you refer to, which prevented me to
change the space to 0. If I can find a reproducable case I will tell you.

The really important issue though, is that the spacing reverts to Default
whenever the component is moved. This is very easy to reproduce and it makes
the layout manager practically unusable, which is really a pity since it
seems to be very good in every other sense. Admittedly, I haven't used it for
serious work because of the spacing problem.

Could you also comment on the lack of layout manager properties? Is this a
bug or is there a reason for not allowing the default spacing to be set?
Comment 3 Tomas Pavek 2005-12-06 09:45:24 UTC
> The really important issue though, is that the spacing reverts to Default
> whenever the component is moved.

When being moved, the components snap at the default preferred distance. When
dropped, new gaps are created as needed. That's how it works. The gap does not
belong to the component - there is no 1:1 relationship.

> Could you also comment on the lack of layout manager properties? Is this
> a bug or is there a reason for not allowing the default spacing to be set?

We simply had not time to do everything. Customizing the default spacing was
considered as a feature of lower priority for the first release. I can see you'd
really need it, but your case is rather special. It should be still possible to
provide the scheme programmatically - for sure for running app, and possibly
also for the design. I can give you more details if interested.
Comment 4 gugrim 2005-12-06 10:32:50 UTC
> I can give you more details if interested.

Yes, I'm very interested!
Comment 5 Tomas Pavek 2005-12-06 11:32:30 UTC
The spacing is handled by LayoutStyle class from the Swing Layout Library (you
can download complete sources as NB project from http://swing-layout.dev.java.net).

What I suggest you to try is to provide your own implementation of LayoutStyle
class that would return 0 for your components and delegate to the default impl.
for the other cases. There is a static method setSharedInstance(LayoutStyle
layoutStyle) that allows you to register your own instance, and a static method
LayoutStyle getSharedInstance() that you should call first to get the default
impl. you then delegate to in your specialized implementation.

There are two methods to override that control the spacing: getContainerGap and
getPreferredGap. Here you would test if the incomming components are your
special components and return 0, or call the default impl.

This all should work for executing your app - as you can easily register your
LayoutStyle. It is however problematic to get it registered in the GUI builder
environment - one way is e.g. a static initializer of some class all your
components must load. This of course makes your components depend on the Swing
Layout library and the special LayoutStyle impl. must be packed with the
components...

For the next release we'll try to allow to register the LayoutStyle in the GUI
builder in a cleaner way.
Comment 6 Tomas Pavek 2005-12-06 11:44:08 UTC
I've found one case when the explicitly modified spaces could be preserved:

If you two components next to each other with zero gap then inserting a third
component on the place of the second should preserve the original gap.

But overall the "space around feature" is meant just for fine-tuning the layout,
not for defining a spacing scheme to keep. Thus I'm lowering the priority to P3
corresponding to the problem above. If you find another specific case, just add
it here. Thanks
Comment 7 gugrim 2005-12-07 08:40:55 UTC
Thanks, for the tips. I've managed to install a LayoutStyle that does what you
adviced. Also, I think I understand now why you can't specify the default gaps
as layout manager properties. The GroupLayout doesn't seem to have any public
properties for tailoring the style! Perhaps the best way would be to enhance
it to allow paddings to be specified as constructor parameters, like FlowLayout.
Comment 8 Jan Stola 2008-03-10 15:06:45 UTC
This issue turned out to be about possibility to change the runtime and design-time LayoutStyle. While I understand 
that it may be painfull not having this support (in some special cases), it is more an enhancement than a pure defect.