重新验证 JPanel 的父框架

发布于 2024-09-01 04:28:38 字数 130 浏览 1 评论 0原文

当我显示/隐藏字段时,我希望我的面板适合框架。我如何通知父框架重新验证?

我考虑过将框架传递给面板的构造函数,但我认为可能有一种方法已经完成了。我记得 JPanel 中有一个 protected 属性,但没有..也许我记错了组件。

I want my panel to fit the frame when I show/hide fields. How could I notify to the parent frame to revalidate?

I thought about pass the frame to my panel's constructor, but I think may have a way this is already done. I remember that there was a protected attribute in JPanel, but there isn't.. maybe i remembering the wrong component.

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

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

发布评论

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

评论(3

南笙 2024-09-08 04:28:38

我需要显示/隐藏我的一些字段
面板,我希望面板适合
框架。

您的意思是像摘要/详细信息视图一样,并且您希望更改框架大小?然后尝试:

SwingUtilities.windowForComponent(...).pack();

I need show/hide some fields of my
panel, and I want the panel to fit the
frame.

You mean like a summary/details view and you want the frame size to change? Then try:

SwingUtilities.windowForComponent(...).pack();

酷到爆炸 2024-09-08 04:28:38

您可以将面板中的 addNotify 重写为某些内容:

public void addNotify() {
    getParent().revalidate();
    repaint();
    super.addNotify();
}

但不确定这是否是您的意思。

you could override the addNotify in the panel into something:

public void addNotify() {
    getParent().revalidate();
    repaint();
    super.addNotify();
}

Not sure if that's what you mean though.

意中人 2024-09-08 04:28:38
SwingUtilities.getRoot(this).invalidate();
SwingUtilities.getRoot(this).invalidate();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文