Swing 容器和控制器不遵守应用于它们的设置?

发布于 2024-12-09 23:58:02 字数 258 浏览 0 评论 0原文

我使用的是 Netbeans 7,在设计 Swing 容器和控制器时遇到了最不寻常的情况。由于某些未知的原因,在某些情况下,容器或控制器决定选择自己的大小和尺寸,尽管我已尝试在代码级别和每个容器的属性视图中设置这些参数。有时我的一些 jButton 的文本标签未显示,有时我会得到不同大小的 JDialog 或 JPanel,即使我在设计视图和代码级别都指定了它们。

有没有人对这种奇怪的行为有任何解释,或者有人在 Netbeans 上遇到过类似的问题吗?!

亲切的问候

I'm using Netbeans 7 and I'm running into the most unusual situations when designing the Swing Containers and Controllers. For some unknown reason and at some situation the Containers or Controllers decide to choose their own sizes and dimensions even though I have tried setting these parameters both at the code level and the properties view of each of those containers. Sometimes I get the Text label of some of my jButtons not showing, sometimes I get a different size JDialog or JPanel even though I both specified them at the design view and at the code level.

Does anyone have any explanation for this odd behaviours or has anyone ran into a problem like that on Netbeans?!

Kind Regards

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

独木成林 2024-12-16 23:58:02

您可能通过内置的 FreeLayoutGridBagLayout 放置容器。对于有关内置选项和函数的具体问题,请访问 Netbeans 论坛,但看起来没有问题的答案,

Java 桌面应用程序 (JSR296) 是很长一段时间不受支持的框架,我不知道原因,也不知道为什么(以避免任何猜测)

Java Desktop Aplication 是基于关于 Java AWT & Swing Components

考虑使用标准 Swing JComponents 由标准 LayoutManagers 放置,而不是重新生成un_supported Framework,关于 Swing 是否有当前(标记的)Swing 论坛,

也许太舒服了,从准备好的选项中拖放Components,但有麻烦的自定义(是非用户友好,我的观点)

为了得到好的答案,你必须根据 SSCCE 提出问题

you probably layed the Containers by built-in FreeLayout, or GridBagLayout. For specific questions about built-in oprions and funcions is there Netbeans Forums, but looks like as witouth answers to the questions,

Java Desktop Aplication (JSR296) is long time non-supported Framework, I don't know reason and don't know why (to avoid any speculations)

Java Desktop Aplication is based on Java AWT & Swing Components

consider to using standard Swing JComponents layed by standard LayoutManagers, rather than to reicarnate un_supported Framework, about Swing is there current (tagged) Swing Forum

maybe is too confortable drag_and_drop Components from prepared options, but with bothering customizations (is non_user-friedly, my view)

for good answer you have to ask question based on SSCCE

无所谓啦 2024-12-16 23:58:02

组件的大小根据容器当前的 LayoutManager 规则进行调整。每个管理器都有自己的一套管理组件大小的规则。例如,如果您使用的是 BorderLayout (输入链接说明这里),并在中心部分添加一个组件,它将使用所有可用空间,忽略您的尺寸设置(包括最小/首选/最大尺寸)。但是,如果您使用 GridBagLayout,您可以指定如何在组件之间分配可用空间。

看来您的问题是布局管理器问题。大多数时候,默认管理器并不是您想要使用的管理器。请务必根据您的需要设置正确的 LayoutManager 实例。如果您需要更多指导,可以在网络上找到许多有关布局管理器的教程。 这个来自Oracle(以前由Sun编写,当时它仍然拥有该东西)。

Components are resized based on the current LayoutManager rules of your container. Each manager has its own set of rules for managing components' size. For instance, if you are using a BorderLayout (enter link description here), and add a component in the center part, it will use all of the available space, ignoring your size settings (including the minimum/preferred/maximum size). However, if you are using a GridBagLayout, you can specify how free space is allocated among components.

It seems that your problem is a layout manger problem. Most of the time, the default manager will not be the one you want to use. Be sure to set the correct LayoutManager instance for your needs. If you need more guidance, many tutorials on layout managers are available on the web. This one comes from Oracle (previously written by Sun when it still owned the thing).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文