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.
Summary: | [50cat] Space Around Component forced to Default | ||
---|---|---|---|
Product: | guibuilder | Reporter: | gugrim <gugrim> |
Component: | Code | Assignee: | issues@guibuilder <issues> |
Status: | NEW --- | ||
Severity: | blocker | ||
Priority: | P3 | ||
Version: | 5.x | ||
Hardware: | PC | ||
OS: | Linux | ||
Issue Type: | ENHANCEMENT | Exception Reporter: |
Description
gugrim
2005-12-03 18:06:34 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. 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? > 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. > I can give you more details if interested.
Yes, I'm very interested!
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. 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 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. 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. |